The .env
file is required, check .env.example for details
Server launches in several steps
- Environment variables are loaded with
dotenv
- Database is created if it does not exist
- If
MIGRATIONS_ON_STARTUP
environment variable is set toenabled
, migrations are applied - Database connection created
- Database models are loaded
- Socket server is launched
Launch the server in development
npm run dev
Database scheme is presented on a scheme file (scheme is created with https://diagrams.net)
Application checks database existence and creates database automatically when it is launched for the first time
All of the database changes should be done using migrations
- Update the graphical representation of the database
- Generate a new migration file and add all of the necessary changes
- Update the model or create model in the src/database/models directory
- Update the type or create type in the src/types/database.ts file
- Run migration process manually or launch the project if migrations are applied automatically
Migration files are located in the database/migrations directory
Migrations can be applied automatically by setting the MIGRATIONS_ON_STARTUP
environment variable to enabled
Apply existing migrations manually
npm run migrate
Generate a new migration file
npx sequelize-cli migration:generate --name <MIGRATION_NAME>
Additional documentation: https://sequelize.org/docs/v7/other-topics/migrations