Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Setting up a MySQL database for the app

Katja Durrani edited this page May 18, 2020 · 10 revisions

Create a database with initial tables and a first user

(This is again written on the basis that we use Laradock, but should be easy to transfer to other environments)

Set up the database

1. Set environment variables for Laradock and the app

Below are the configurations for the two .env files. It does not matter what you choose for names (database, user and password), as long as they are the same for both files.

codehub-mentorships/.env:

- DB_CONNECTION=mysql
- DB_HOST=mysql
- DB_PORT=3306
- DB_DATABASE=mentoring
- DB_USERNAME=mentor
- DB_PASSWORD=bristol

laradock/.env:

Make sure to set the version to 5.7 as otherwise it is easy to run into compatibility issues

### MYSQL #################################################
MYSQL_VERSION=5.7
MYSQL_DATABASE=mentoring
MYSQL_USER=mentor
MYSQL_PASSWORD=bristol
MYSQL_PORT=3306
MYSQL_ROOT_PASSWORD=root
MYSQL_ENTRYPOINT_INITDB=./mysql/docker-entrypoint-initdb.d

2. Start docker containers with the new configuration

Inside the laradock folder, run docker-compose up -d nginx mysql

3. Create database

Inside laradock, run docker-compose exec mysql mysql -u root -p, then enter your db root password This should take you onto the mysql command line inside the mysql docker container.

Now you can create the database:

mysql>  CREATE DATABASE mentoring;

This is all we need to do in this container; \q will take you out of mysql and the container.

4. Create initial tables from inside the workspace container, using the php artisan tool

Enter the workspace container with docker-compose exec workspace bash.
Inside the container, you should be in the /var/www directory Then type
php artisan migrate This will create a migrations table, and run the migrations that can be found in the _database/migrations_directory inside codehub-mentorships, setting up users, password_resets and failed_jobs tables.

Create the first user

We have no registration set up on the app yet, but if you fetch this branch you can create a first user from the commandline https://github.com/CodeHubOrg/codehub-mentorships/tree/katja/inertia-login
Inside the workspace docker container, run php artisan make:superuser (at this stage just a normal user really) This will then print out email -- by default [email protected]­ -- and password of the user

After rebuilding the frontend of the app with npm run dev or yarn dev you should be able to use these credentials to log in at localhost/login

Clone this wiki locally