Skip to content

Commit

Permalink
move the uuid fix into the DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Jan 24, 2024
1 parent 3451aed commit 4632524
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
6 changes: 4 additions & 2 deletions packages/cli/src/databases/dsl/Column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ export class Column {
options.type = isPostgres ? 'timestamptz' : 'datetime';
} else if (type === 'json' && isSqlite) {
options.type = 'text';
} else if (type === 'uuid' && isMysql) {
} else if (type === 'uuid') {
// mysql does not support uuid type
options.type = 'varchar(36)';
if (isMysql) options.type = 'varchar(36)';
// we haven't been defining length on "uuid" varchar on sqlite
if (isSqlite) options.type = 'varchar';
}

if ((type === 'varchar' || type === 'timestamp') && length !== 'auto') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,17 @@ const tableName = 'project';
const relationTableName = 'project_relation';

export class CreateProject1705928727784 implements ReversibleMigration {
async up({ dbType, schemaBuilder: { createTable, column } }: MigrationContext) {
async up({ schemaBuilder: { createTable, column } }: MigrationContext) {
await createTable(tableName).withColumns(
column('id').varchar(36).primary.notNull,
column('name').varchar(255),
column('type').varchar(36),
).withTimestamps;

let userIdColumn = column('userId').varchar().primary.notNull;
// Foreign key will fail because the user ID column is an actual
// uuid column in postgres
if (dbType === 'postgresdb') {
userIdColumn = column('userId').uuid.primary.notNull;
}

await createTable(relationTableName)
.withColumns(
column('projectId').varchar(36).primary.notNull,
userIdColumn,
column('userId').uuid.primary.notNull,
column('role').varchar().notNull,
)
.withIndexOn('projectId')
Expand Down

0 comments on commit 4632524

Please sign in to comment.