Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Feat/typeorm migration available): Implement TypeORM migration #39

Merged
merged 7 commits into from
Feb 7, 2025

Conversation

Ho-s
Copy link
Owner

@Ho-s Ho-s commented Feb 5, 2025

Migration setup and usage

This project uses TypeORM's migration feature to manage database schema changes. Follow the steps below to generate and apply migrations.

Note

  1. The custom typeorm command defined in package.json is configured for NODE_ENV=production.
  2. Migrations are intended for production use, while typeorm synchronize should be used for development purposes.
  3. You can see the detailed configuration code here
  4. As you can see from the configuration code, migration files must be located in the subdirectory of /src/common/database/migrations/${name}.

1. Generate a migration file

To reflect new changes in the database, you need to first generate a migration file.

yarn migration:generate ./src/common/database/migrations/init

you can change the name of migration by replacing init

2. Run the Migration

To apply the generated migration to the database, run the following command:

yarn migration:run

3. Revert a Migration

To roll back the last applied migration, use the following command:

yarn migration:revert

4. Check Migration Status

To view the current status of your migrations, run:

yarn migration:show

Create Migration Command

You can also directly create a migration file using the following typeorm command:

yarn migration:create ./src/common/database/migrations/init

This command generates an empty migration file where you can manually add your schema changes.

ref: #38

@Ho-s Ho-s self-assigned this Feb 5, 2025
@Ho-s Ho-s mentioned this pull request Feb 5, 2025
@Ho-s Ho-s merged commit f2cde67 into main Feb 7, 2025
1 check passed
@Ho-s Ho-s deleted the feat/typeorm-migration-able branch February 7, 2025 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant