Skip to content

Commit

Permalink
fix: refactor user groups to permissions relation gf-78 (#116)
Browse files Browse the repository at this point in the history
* fix: refactor user groups to permissions relation gf-78

* fix: remove unnecessary column names gf-78
  • Loading branch information
s1rserg authored Aug 30, 2024
1 parent a5b61dc commit 9bcbf98
Showing 1 changed file with 40 additions and 0 deletions.
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 };

0 comments on commit 9bcbf98

Please sign in to comment.