User management - login / sign up / roles assigned to users ( organisers, admins and normal users)
git clone https://github.com/BEOpenSourceCollabs/EventManagementCore
cd EventManagementCore
Create a db.env
file in project root with following variables
# Pgadmin credentials
PGADMIN_DEFAULT_EMAIL=admin@admin.com
PGADMIN_DEFAULT_PASSWORD=12345
# Postgresql credentials
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
you can change these values if you want. If you change postgresql credentials, make sure to updated the OWNER
in init.sql
Setup the application environment and add the database configuration.
Create a .env
file in the project root with the following variables:
# Database configuration
DATABASE_HOST=127.0.0.1
DATABASE_USER=postgres
DATABASE_PASSWORD=postgres
DATABASE_NAME=event-mgmt-db
DATABASE_PORT=5432
DATABASE_SSL_MODE=disable
ACCESS_TOKEN_SECRET=test
REFRESH_TOKEN_SECRET=test
Ensure to update these to match your database configuration (these are set in db.env
for development).
To run the application and all required services within docker.
docker compose up
Name | Address |
---|---|
Server Base | http://localhost:8081 |
Documentation | http://localhost:8081/swagger |
PGAdmin | https://localhost:8888/ |
To login to the PGAdmin dashboard use the email and password set in
PGADMIN_DEFAULT_EMAIL
andPGADMIN_DEFAULT_PASSWORD
This runs the application without docker.
You will need to ensure you have a postgres database setup, and run the migrations.
You may need to do that manually.
make run
make test
# or
make test.unit
Best practice for running the application is as follows.
After completing prerequisit steps to setup and configure the application the docker compose can be used to run the development environment.
docker compose watch
Using
watch
will automatically syncronize changes to the running container and restart the application.
This section shows example usage of the docker-dev.sh
script, which builds only the event-mgmt-core image and runs it in a container. You will have to setup and configure the database before running.
This is akin to running
make run
but within a docker container instead.
./docker-dev.sh
If you want to run the database from docker-compose.yml
and use that you can do the following:
# start only db
docker compose up db
# optionally you could start both the db and pgadmin
docker compose up db pgadmin
Note: the database containers name 'event-mgmt-postgres' can be used as the host in your
.env
file when using one of the above commands to run postgres within a container.
Then run the application:
./docker-dev.sh
To work with database migrations, golang-migrate cli needs to be installed and working.
The init.sql
file is responsible for creating an empty database. This file is automatically executed by docker-compose
during the first run. After the initial setup, database migrations handle subsequent changes to the database schema.
Each migration is versioned and follows a sequential numbering format, starting with 000001
.
Each migration consists of two files -
<SEQUENCE_NUMBER>_<MIGRATION_NAME>.up.sql
: This file contains the SQL statements to apply the changes (migration).<SEQUENCE_NUMBER>_<MIGRATION_NAME>.down.sql
: This file contains the SQL statements to undo the changes (rollback).To apply all the migrations from first, all the way to the latest
$ make migrate.all.up
To view current version of database (current version means current migration # it is at),
$ make migrate.version
To create a new migration,
$ make migrate.create NAME=name_of_your_migration
To goto a specific version of database ,
$ make migrate.goto V=version_you_want_to_goto
Example: make migrate.goto V=4
To undo all the migrations and go to initial state,
$ make migrate.all.down