-
Notifications
You must be signed in to change notification settings - Fork 50.1k
feat(core): Add migration to add property userActivated to user settings (no-changelog) #5940
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6f25d57
Add userActivated migration
RicardoE105 86bae30
Fix migration logic
RicardoE105 610222f
Sync master
RicardoE105 8118cf7
Remove duplication when retrieving the activated users
RicardoE105 17dc5e8
Fix bug updating settings in mysql
RicardoE105 cdc593c
Make userSettings type conform with naming convention
RicardoE105 f95c774
Disable naming convention rule only in IDatabaseCollections interface
RicardoE105 031f0de
Fix down method in Postgres migration
RicardoE105 2727b35
Reset '{}' to NULL when reversing migration
RicardoE105 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/cli/src/databases/migrations/mysqldb/1681134145996-AddUserActivatedProperty.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
| import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers'; | ||
| import type { UserSettings } from '@/Interfaces'; | ||
|
|
||
| export class AddUserActivatedProperty1681134145996 implements MigrationInterface { | ||
| name = 'AddUserActivatedProperty1681134145996'; | ||
|
|
||
| async up(queryRunner: QueryRunner): Promise<void> { | ||
| logMigrationStart(this.name); | ||
|
|
||
| const tablePrefix = getTablePrefix(); | ||
|
|
||
| const activatedUsers: UserSettings[] = await queryRunner.query( | ||
| `SELECT DISTINCT sw.userId AS id, | ||
| JSON_SET(COALESCE(u.settings, '{}'), '$.userActivated', true) AS settings | ||
| FROM ${tablePrefix}workflow_statistics AS ws | ||
| JOIN ${tablePrefix}shared_workflow as sw | ||
| ON ws.workflowId = sw.workflowId | ||
| JOIN ${tablePrefix}role AS r | ||
| ON r.id = sw.roleId | ||
| JOIN ${tablePrefix}user AS u | ||
| ON u.id = sw.userId | ||
| WHERE ws.name = 'production_success' | ||
| AND r.name = 'owner' | ||
| AND r.scope = 'workflow'`, | ||
| ); | ||
|
|
||
| const updatedUsers = activatedUsers.map((user) => | ||
| queryRunner.query( | ||
| `UPDATE ${tablePrefix}user SET settings = '${JSON.stringify(user.settings)}' WHERE id = '${ | ||
| user.id | ||
| }' `, | ||
| ), | ||
| ); | ||
|
|
||
| await Promise.all(updatedUsers); | ||
|
|
||
| if (!activatedUsers.length) { | ||
| await queryRunner.query( | ||
| `UPDATE ${tablePrefix}user SET settings = JSON_SET(COALESCE(settings, '{}'), '$.userActivated', false)`, | ||
| ); | ||
| } else { | ||
| const activatedUserIds = activatedUsers.map((user) => `'${user.id}'`).join(','); | ||
|
|
||
| await queryRunner.query( | ||
| `UPDATE ${tablePrefix}user SET settings = JSON_SET(COALESCE(settings, '{}'), '$.userActivated', false) WHERE id NOT IN (${activatedUserIds})`, | ||
| ); | ||
| } | ||
|
|
||
| logMigrationEnd(this.name); | ||
| } | ||
|
|
||
| async down(queryRunner: QueryRunner): Promise<void> { | ||
| const tablePrefix = getTablePrefix(); | ||
| await queryRunner.query( | ||
| `UPDATE ${tablePrefix}user SET settings = JSON_REMOVE(settings, '$.userActivated')`, | ||
| ); | ||
RicardoE105 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| await queryRunner.query(`UPDATE ${tablePrefix}user SET settings = NULL WHERE settings = '{}'`); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/cli/src/databases/migrations/postgresdb/1681134145996-AddUserActivatedProperty.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
| import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers'; | ||
| import type { UserSettings } from '@/Interfaces'; | ||
|
|
||
| export class AddUserActivatedProperty1681134145996 implements MigrationInterface { | ||
| name = 'AddUserActivatedProperty1681134145996'; | ||
|
|
||
| async up(queryRunner: QueryRunner): Promise<void> { | ||
| logMigrationStart(this.name); | ||
|
|
||
| const tablePrefix = getTablePrefix(); | ||
|
|
||
| const activatedUsers: UserSettings[] = await queryRunner.query( | ||
| `SELECT DISTINCT sw."userId" AS id, | ||
| JSONB_SET(COALESCE(u.settings::jsonb, '{}'), '{userActivated}', 'true', true) as settings | ||
| FROM ${tablePrefix}workflow_statistics ws | ||
| JOIN ${tablePrefix}shared_workflow sw | ||
| ON ws."workflowId" = sw."workflowId" | ||
| JOIN ${tablePrefix}role r | ||
| ON r.id = sw."roleId" | ||
| JOIN "${tablePrefix}user" u | ||
| ON u.id = sw."userId" | ||
| WHERE ws.name = 'production_success' | ||
| AND r.name = 'owner' | ||
| AND r.scope = 'workflow'`, | ||
| ); | ||
|
|
||
| const updatedUsers = activatedUsers.map((user) => | ||
| queryRunner.query( | ||
| `UPDATE "${tablePrefix}user" SET settings = '${JSON.stringify( | ||
| user.settings, | ||
| )}' WHERE id = '${user.id}' `, | ||
| ), | ||
| ); | ||
|
|
||
| await Promise.all(updatedUsers); | ||
|
|
||
| if (!activatedUsers.length) { | ||
| await queryRunner.query( | ||
| `UPDATE "${tablePrefix}user" SET settings = JSONB_SET(COALESCE(settings::jsonb, '{}'), '{userActivated}', 'false', true)`, | ||
| ); | ||
| } else { | ||
| const activatedUserIds = activatedUsers.map((user) => `'${user.id}'`).join(','); | ||
|
|
||
| await queryRunner.query( | ||
| `UPDATE "${tablePrefix}user" SET settings = JSONB_SET(COALESCE(settings::jsonb, '{}'), '{userActivated}', 'false', true) WHERE id NOT IN (${activatedUserIds})`, | ||
| ); | ||
| } | ||
|
|
||
| logMigrationEnd(this.name); | ||
| } | ||
|
|
||
| async down(queryRunner: QueryRunner): Promise<void> { | ||
| const tablePrefix = getTablePrefix(); | ||
| await queryRunner.query( | ||
| `UPDATE "${tablePrefix}user" SET settings = settings::jsonb - 'userActivated'`, | ||
| ); | ||
| await queryRunner.query( | ||
| `UPDATE "${tablePrefix}user" SET settings = NULL WHERE settings::jsonb = '{}'::jsonb`, | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/cli/src/databases/migrations/sqlite/1681134145996-AddUserActivatedProperty.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
| import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers'; | ||
| import type { UserSettings } from '@/Interfaces'; | ||
|
|
||
| export class AddUserActivatedProperty1681134145996 implements MigrationInterface { | ||
| name = 'AddUserActivatedProperty1681134145996'; | ||
|
|
||
| async up(queryRunner: QueryRunner): Promise<void> { | ||
| logMigrationStart(this.name); | ||
|
|
||
| const tablePrefix = getTablePrefix(); | ||
|
|
||
| const activatedUsers: UserSettings[] = await queryRunner.query( | ||
| `SELECT DISTINCT sw.userId AS id, | ||
| JSON_SET(COALESCE(u.settings, '{}'), '$.userActivated', JSON('true')) AS settings | ||
| FROM ${tablePrefix}workflow_statistics AS ws | ||
| JOIN ${tablePrefix}shared_workflow AS sw | ||
| ON ws.workflowId = sw.workflowId | ||
| JOIN ${tablePrefix}role AS r | ||
| ON r.id = sw.roleId | ||
| JOIN ${tablePrefix}user AS u | ||
| ON u.id = sw.userId | ||
| WHERE ws.name = 'production_success' | ||
| AND r.name = 'owner' | ||
| AND r.scope = "workflow"`, | ||
| ); | ||
|
|
||
| const updatedUsers = activatedUsers.map((user) => | ||
| queryRunner.query( | ||
| `UPDATE ${tablePrefix}user SET settings = '${user.settings}' WHERE id = '${user.id}' `, | ||
| ), | ||
| ); | ||
|
|
||
| await Promise.all(updatedUsers); | ||
|
|
||
| if (!activatedUsers.length) { | ||
| await queryRunner.query( | ||
| `UPDATE ${tablePrefix}user SET settings = JSON_SET(COALESCE(settings, '{}'), '$.userActivated', JSON('false'))`, | ||
| ); | ||
| } else { | ||
| const activatedUserIds = activatedUsers.map((user) => `'${user.id}'`).join(','); | ||
| await queryRunner.query( | ||
| `UPDATE ${tablePrefix}user SET settings = JSON_SET(COALESCE(settings, '{}'), '$.userActivated', JSON('false')) WHERE id NOT IN (${activatedUserIds})`, | ||
| ); | ||
| } | ||
|
|
||
| logMigrationEnd(this.name); | ||
| } | ||
|
|
||
| async down(queryRunner: QueryRunner): Promise<void> { | ||
| const tablePrefix = getTablePrefix(); | ||
| await queryRunner.query( | ||
| `UPDATE ${tablePrefix}user SET settings = JSON_REMOVE(settings, '$.userActivated')`, | ||
| ); | ||
| await queryRunner.query(`UPDATE ${tablePrefix}user SET settings = NULL WHERE settings = '{}'`); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.