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

⬇️ Merge release v5.2 to dev branch with typeorm syntax updates for feature flag #1878

Merged
merged 5 commits into from
Sep 4, 2024

Conversation

ppratikcr7
Copy link
Collaborator

@ppratikcr7 ppratikcr7 commented Aug 29, 2024

Context

This PR is to resolve #1875. Here we want to pull the typeORM v0.3.0 update related changes to dev branch to release v6.0 with feature flags.

Summary

Here I have made a new branch release/v6.0 from dev branch and pulled in release/v5.2 branch. Updated typeorm syntax for feature flag related code.

Key Changes

  • Updated typeORM syntax for feature flag related code in dev branch.
  • In typeORM v0.3.0 { primary: true } option to define a column as primary key is not supported for relational columns like @ManyToMany, @OneToMany. We need to define separate @PrimaryColumn and use @JoinColum with the relational column. This is done in this PR for feature flag related models.
  • In the typeORMLoader.ts file, we need to add any new entities/models that we create and also add any new migrations class.
  • Created a migration file for the model changes made.
  • Updated migration commands as with typeorm update the old command seems to generate migration files in wrong directory.

@ppratikcr7 ppratikcr7 self-assigned this Aug 29, 2024
@ppratikcr7 ppratikcr7 changed the title ⬇️ Merge release v5.2 to dev branch with typeorm syntax updates for feature flag #1876 ⬇️ Merge release v5.2 to dev branch with typeorm syntax updates for feature flag Aug 29, 2024
@ppratikcr7 ppratikcr7 added this to the Program Increment PI12 milestone Aug 29, 2024
@ppratikcr7 ppratikcr7 added the priority: high High priority issue label Aug 29, 2024
@bcb37
Copy link
Collaborator

bcb37 commented Aug 29, 2024

  • In the typeORMLoader.ts file, we need to add any new entities/models that we create and also add any new migrations class.

That's really annoying. Why can't Typeorm keep track of and discover these things anymore? I know I'll forget to do this step a lot.

import { removeGroupIdFromIndividualExclusion1721124249413 } from '../database/migrations/1721124249413-removeGroupIdFromIndividualExclusion';
import { featureFlagFilterModeChangeDefault1722540825048 } from '../database/migrations/1722540825048-featureFlagFilterModeChangeDefault';

const entities = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we not just use env.app.dirs.entities instead of having to define this and update it all the time? I tested it locally and it works.

UserStratificationFactor,
];

export const migrations = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. I was able to use env.app.dirs.migrations and did not have to define this variable.

migrations: env.app.dirs.migrations,
});
return connection;
migrations: migrations,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I successfully ran tests using env.app.dirs.migration instead of importing the variable and it worked fine.

Copy link
Collaborator

@VivekFitkariwala VivekFitkariwala Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's deprecated and will be removed from the 0.4.0 version. Check the changelog Breaking Change

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets go with @bcb37 suggestion till they force us to upgrade :)

password: env.db.password,
logging: env.db.logging as LoggerOptions,
entities: env.app.dirs.entities,
migrations: migrations,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too

"migration:run": "./node_modules/.bin/ts-node -r tsconfig-paths/register ./node_modules/.bin/typeorm migration:run",
"migration:generate": "./node_modules/.bin/ts-node -r tsconfig-paths/register ./node_modules/.bin/typeorm migration:generate -d src/loaders/typeormLoader.ts",
"migration:create": "./node_modules/.bin/ts-node -r tsconfig-paths/register ./node_modules/.bin/typeorm migration:create -d src/loaders/typeormLoader.ts",
"migration:run": "./node_modules/.bin/ts-node -r tsconfig-paths/register ./node_modules/.bin/typeorm migration:run -d src/loaders/typeormLoader.ts",
"migration:revert": "./node_modules/.bin/ts-node -r tsconfig-paths/register ./node_modules/.bin/typeorm migration:revert"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add the -d flag to the revert script here too

bcb37
bcb37 previously requested changes Aug 29, 2024
Copy link
Collaborator

@bcb37 bcb37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things I noticed, which were probably in the original pr.
Also, should the migration in the top level 1724745446870-typeormv3-featureFlagUpdates.ts be moved?

@@ -0,0 +1,50 @@
import { MigrationInterface, QueryRunner } from "typeorm";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file needed?

Copy link
Collaborator Author

@ppratikcr7 ppratikcr7 Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we need this, somehow the file was created in the Upgrade directory due to recent changes to migration script. Will look into this.

@ppratikcr7
Copy link
Collaborator Author

  • In the typeORMLoader.ts file, we need to add any new entities/models that we create and also add any new migrations class.

That's really annoying. Why can't Typeorm keep track of and discover these things anymore? I know I'll forget to do this step a lot.

Right, I was also feeling the same as it was done in the old PR for typeorm changes and I was going to look for a solution. Yes, indeed env.app.dirs.entities and env.app.dirs.migration works fine. Thanks :)

@ppratikcr7
Copy link
Collaborator Author

ppratikcr7 commented Sep 3, 2024

@bcb37 @VivekFitkariwala Made changes as requested to remove excess changes to the datasource typeLoader file related to annoying updates to the entities and migration on each new addition. We can update once its forced in typeorm v0.4.

Also, checked the migration scripts and resolved them to generate migration files in proper directory src/database/migrations. The change required to run the migration script is as below for the generate and create cli commands (we need to pass the migration file name as an argument name):

name=migration-name npm run migration:generate
name=migration-name npm run migration:create

The other two migration scripts for run and revert should remain the same:

npm run migration:run
npm run migration:revert

Also, I had to update the typeormloader to have a default export of the datasource due to following error after removing the entities and migrations export from it:

Error: Given data source file must contain export of a DataSource instance

@ppratikcr7
Copy link
Collaborator Author

Once, this is approved, will add these changes in the slack and gitbook documentation.

@danoswaltCL danoswaltCL merged commit 154c558 into dev Sep 4, 2024
12 checks passed
@danoswaltCL danoswaltCL deleted the feature-flags/merge-typeorm-v0.3-updates branch September 4, 2024 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: high High priority issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge release v5.2 into dev branch (FF)
4 participants