Skip to content

Commit

Permalink
migrated to new api fo constraints away from deprecated api
Browse files Browse the repository at this point in the history
  • Loading branch information
rizen committed Jan 21, 2025
1 parent 21b5170 commit f6488bd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions ving/drizzle/schema/APIKey.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const APIKeyTable = mysqlTable('apikeys',
privateKey: varchar('privateKey', { length: 39 }).notNull().default(''),
userId: bigint('userId', {mode:'number', unsigned: true}).notNull()
},
(table) => ({
apikeys_user_90ada4_fk: foreignKey({ name: "apikeys_user_90ada4_fk", columns: [table.userId], foreignColumns: [UserTable.id]}).onDelete("cascade").onUpdate("cascade")
})
(table) => ([
foreignKey({ name: "apikeys_user_90ada4_fk", columns: [table.userId], foreignColumns: [UserTable.id]}).onDelete("cascade").onUpdate("cascade")
])
);

4 changes: 2 additions & 2 deletions ving/drizzle/schema/CronJob.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const CronJobTable = mysqlTable('cronjobs',
enabled: boolean('enabled').notNull().default(true),
note: text('note').notNull()
},
(table) => ({
(table) => ([

})
])
);

6 changes: 3 additions & 3 deletions ving/drizzle/schema/S3File.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const S3FileTable = mysqlTable('s3files',
icon: mysqlEnum('icon', ['pending','thumbnail','extension','self']).notNull().default('pending'),
userId: bigint('userId', {mode:'number', unsigned: true}).notNull()
},
(table) => ({
s3files_user_40cb3d4d_fk: foreignKey({ name: "s3files_user_40cb3d4d_fk", columns: [table.userId], foreignColumns: [UserTable.id]}).onDelete("cascade").onUpdate("cascade")
})
(table) => ([
foreignKey({ name: "s3files_user_40cb3d4d_fk", columns: [table.userId], foreignColumns: [UserTable.id]}).onDelete("cascade").onUpdate("cascade")
])
);

10 changes: 5 additions & 5 deletions ving/drizzle/schema/User.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export const UserTable = mysqlTable('users',
bio: mediumText('bio').notNull(),
avatarId: bigint('avatarId', {mode:'number', unsigned: true}).default(null)
},
(table) => ({
usernameIndex: uniqueIndex('usernameIndex').on(table.username),
emailIndex: uniqueIndex('emailIndex').on(table.email),
users_avatar_39d62890_fk: foreignKey({ name: "users_avatar_39d62890_fk", columns: [table.avatarId], foreignColumns: [S3FileTable.id]}).onDelete("set null").onUpdate("no action")
})
(table) => ([
uniqueIndex('usernameIndex').on(table.username),
uniqueIndex('emailIndex').on(table.email),
foreignKey({ name: "users_avatar_39d62890_fk", columns: [table.avatarId], foreignColumns: [S3FileTable.id]}).onDelete("set null").onUpdate("no action")
])
);

10 changes: 5 additions & 5 deletions ving/generator/drizzletable.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ export const makeBaseTable = (schema) => {
const fields = [prop.name, ...prop.uniqueQualifiers];
const composite = fields.join('_');
const key = composite.substring(0, 48) + '_' + miniHash(composite) + '_uq';
specialConstraints.push(`${key}: unique('${key}').on(table.${fields.join(', table.')})`);
specialConstraints.push(`unique('${key}').on(table.${fields.join(', table.')})`);
}
else {
specialConstraints.push(`${prop.name}Index: uniqueIndex('${prop.name}Index').on(table.${prop.name})`);
specialConstraints.push(`uniqueIndex('${prop.name}Index').on(table.${prop.name})`);
}
}
if (prop.relation && ['parent', 'sibling'].includes(prop.relation.type)) {
const composite = [schema.tableName, prop.relation.name].join('_');
const key = composite.substring(0, 48) + '_' + miniHash(composite) + '_fk';
specialConstraints.push(`${key}: foreignKey({ name: "${key}", columns: [table.${prop.name}], foreignColumns: [${prop.relation?.kind}Table.id]}).onDelete(${prop.required ? '"cascade"' : '"set null"'}).onUpdate(${prop.required ? '"cascade"' : '"no action"'})`);
specialConstraints.push(`foreignKey({ name: "${key}", columns: [table.${prop.name}], foreignColumns: [${prop.relation?.kind}Table.id]}).onDelete(${prop.required ? '"cascade"' : '"set null"'}).onUpdate(${prop.required ? '"cascade"' : '"no action"'})`);
}
}
}
Expand All @@ -31,9 +31,9 @@ export const ${schema.kind}Table = mysqlTable('${schema.tableName}',
{
${columns.join(",\n\t\t")}
},
(table) => ({
(table) => ([
${specialConstraints.join(",\n\t\t")}
})
])
);
`;
}
Expand Down

0 comments on commit f6488bd

Please sign in to comment.