-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refactor user groups to permissions relation gf-78 (#116)
* fix: refactor user groups to permissions relation gf-78 * fix: remove unnecessary column names gf-78
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
apps/backend/src/db/migrations/20240829181900_fix_user_groups_to_permissions.ts
This file contains 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,40 @@ | ||
import { type Knex } from "knex"; | ||
|
||
const TABLE_NAME = "user_groups_to_permissions"; | ||
|
||
const ColumnName = { | ||
PERMISSION_ID: "permission_id", | ||
} as const; | ||
|
||
const PERMISSIONS_TABLE = "permissions"; | ||
const USERS_TABLE = "users"; | ||
|
||
function up(knex: Knex): Promise<void> { | ||
return knex.schema.alterTable(TABLE_NAME, (table) => { | ||
table.dropForeign([ColumnName.PERMISSION_ID]); | ||
table | ||
.integer(ColumnName.PERMISSION_ID) | ||
.unsigned() | ||
.notNullable() | ||
.references("id") | ||
.inTable(PERMISSIONS_TABLE) | ||
.onDelete("CASCADE") | ||
.alter(); | ||
}); | ||
} | ||
|
||
function down(knex: Knex): Promise<void> { | ||
return knex.schema.alterTable(TABLE_NAME, (table) => { | ||
table.dropForeign([ColumnName.PERMISSION_ID]); | ||
table | ||
.integer(ColumnName.PERMISSION_ID) | ||
.unsigned() | ||
.notNullable() | ||
.references("id") | ||
.inTable(USERS_TABLE) | ||
.onDelete("CASCADE") | ||
.alter(); | ||
}); | ||
} | ||
|
||
export { down, up }; |