dropdb postgres
- Note: Stop all DB service connections first.
createdb -U postgres postgres
- Note: Start the DB server beforehand.
php artisan migrate --path=database/migrations/2021_04_30_084401_create_tables.php
php artisan migrate --path=database/migrations/2021_05_02_113342_create_temp_table.php
psql postgres
\COPY temp_table ("userFirstname", "userSurname", "userEmail", "eventDate", "eventType", "eventMessage") FROM 'database/seeders/sample_data.csv' DELIMITER ',' CSV HEADER;
\q
psql -h 127.0.0.1 -d postgres -U postgres -f ./database/seeders/import.sql
psql -h 127.0.0.1 -d postgres -U postgres -f ./database/seeders/manipulate.sql
php artisan migrate --path=database/migrations/2021_05_02_233014_set_tables.php
php artisan serve
php artisan test --testsuite=Feature
- List users:
GET http://127.0.0.1:8000/api/users
- Delete user:
DELETE http://127.0.0.1:8000/api/users/delete/{id}
- List user events:
GET http://127.0.0.1:8000/api/events
- Event count by type:
GET http://127.0.0.1:8000/api/events/grouped
docker build -t php-api-dev . -f ./docker-files/Dockerfile.dev
Flags:
-t
: tag the image (php-api-dev
).
: current directory-f
: path to Dockerfile
Note: Rebuild the image any time you update the Dockerfile.
docker network create php-api-network
- Note: Links the two containers together.
- Note: Current networking config may have issues — requires debugging.
- Reminder: Add
--network="php-api-network"
to yourdocker run
commands.
Postgres:
docker run -p 5432:5432 -it \
-e POSTGRES_DB=postgres \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
--network="php-api-network" postgres:12.6
PHP API:
docker run -it -p 8000:8000 \
-v $PWD:/php-api-run \
--network="php-api-network" php-api-dev
Flags:
-it
: interactive terminal session-p
: port mapping (host:container)-v
: mounts local directory into container$PWD
: current working directoryphp-api-dev
: Docker image tag
Notes:
- Type
exit
to leave the container session. - Clean up unused images/containers to free up system memory.
- Assumes CSV is used to create a new database, not append to an existing one.
- Migrations + seeders were used, but they may not be optimal for this use case.
- Migrations create blank tables, while seeders insert predefined data — we need both simultaneously.
- A raw SQL file is used to transform and align the data post-import.
- Not using Docker mounted volumes or persistent states (for simplicity).
- Containers are networked but not currently communicating — needs diagnosis.
- Future Task: Create a Bash script to automate Docker installation + setup for fresh VMs.
- Endpoints currently lack authentication or stateful sessions.
- Future Task: Add auth middleware, JWT, or session handling.
date
fields should be consistently formatted.- All
id
columns are properly mapped with primary and foreign keys to maintain relational integrity betweenusers
andevents
.