Updates
This commit is contained in:
@@ -31,7 +31,9 @@ export default async function createTable({
|
||||
}
|
||||
|
||||
if (field.foreignKey && !table.isVector) {
|
||||
foreignKeys.push(buildForeignKeyConstraint(field));
|
||||
foreignKeys.push(
|
||||
buildForeignKeyConstraint(field, table.tableName),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,21 +44,21 @@ export default async function createTable({
|
||||
|
||||
if (table.uniqueConstraints) {
|
||||
for (const constraint of table.uniqueConstraints) {
|
||||
if (
|
||||
constraint.constraintTableFields &&
|
||||
constraint.constraintTableFields.length > 0
|
||||
) {
|
||||
const fields = constraint.constraintTableFields
|
||||
.map((field) => MariaDBQuoteGen(field.value))
|
||||
.join(", ");
|
||||
const constraintName =
|
||||
constraint.constraintName ||
|
||||
`unique_${fields.replace(/`/g, "")}`;
|
||||
const columns = (constraint.constraintTableFields || [])
|
||||
.map((field) => field.value)
|
||||
.filter((value): value is string => Boolean(value));
|
||||
|
||||
columnDefinitions.push(
|
||||
`CONSTRAINT ${MariaDBQuoteGen(constraintName)} UNIQUE (${fields})`,
|
||||
);
|
||||
if (columns.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const fields = columns.map((col) => MariaDBQuoteGen(col)).join(", ");
|
||||
const constraintName =
|
||||
constraint.constraintName || `unique_${columns.join("_")}`;
|
||||
|
||||
columnDefinitions.push(
|
||||
`CONSTRAINT ${MariaDBQuoteGen(constraintName)} UNIQUE (${fields})`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user