Skip to content

Commit

Permalink
feat: Add ACL table (#97)
Browse files Browse the repository at this point in the history
* feat: Add ACL table

* fix: Invert drop type and table order

* fix: Lowercase table name

* fix: Rename permission type
  • Loading branch information
LautaroPetaccio committed May 9, 2023
1 parent 94ea224 commit 00f9fb1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/migrations/1677778846950_lists-and-picks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate'

const PICKS_TABLE = 'picks'
const LISTS_TABLE = 'lists'
export const LISTS_TABLE = 'lists'

export const shorthands: ColumnDefinitions | undefined = undefined

Expand Down
30 changes: 30 additions & 0 deletions src/migrations/1683320488882_acl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate'
import { LISTS_TABLE } from './1677778846950_lists-and-picks'

export const shorthands: ColumnDefinitions | undefined = undefined
const ACL_TABLE = 'acl'
const PERMISSION_TYPE = 'permissions'

export async function up(pgm: MigrationBuilder): Promise<void> {
pgm.createType(PERMISSION_TYPE, ['edit', 'view'])
pgm.createTable(ACL_TABLE, {
list_id: {
type: 'uuid',
notNull: true,
unique: false,
references: `${LISTS_TABLE}(id)`,
onDelete: 'CASCADE'
},
permission: { type: 'permissions', notNull: true },
grantee: { type: 'text', notNull: true }
})
pgm.addConstraint(ACL_TABLE, 'list_id_permissions_grantee_primary_key', {
primaryKey: ['list_id', 'permission', 'grantee']
})
}

export async function down(pgm: MigrationBuilder): Promise<void> {
pgm.dropTable(ACL_TABLE)
pgm.dropType(PERMISSION_TYPE)
}

0 comments on commit 00f9fb1

Please sign in to comment.