Updates
This commit is contained in:
@@ -96,6 +96,8 @@ module.exports = async function createTable({
|
||||
////////////////////////////////////////
|
||||
|
||||
let primaryKeySet = false;
|
||||
|
||||
/** @type {import("../../types").DSQL_FieldSchemaType[]} */
|
||||
let foreignKeys = [];
|
||||
|
||||
////////////////////////////////////////
|
||||
@@ -130,8 +132,7 @@ module.exports = async function createTable({
|
||||
|
||||
if (foreignKey) {
|
||||
foreignKeys.push({
|
||||
fieldName: fieldName,
|
||||
...foreignKey,
|
||||
...column,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -161,14 +162,14 @@ module.exports = async function createTable({
|
||||
|
||||
if (foreignKeys[0]) {
|
||||
foreignKeys.forEach((foreighKey, index, array) => {
|
||||
const {
|
||||
fieldName,
|
||||
destinationTableName,
|
||||
destinationTableColumnName,
|
||||
cascadeDelete,
|
||||
cascadeUpdate,
|
||||
foreignKeyName,
|
||||
} = foreighKey;
|
||||
const fieldName = foreighKey.fieldName;
|
||||
const destinationTableName =
|
||||
foreighKey.foreignKey?.destinationTableName;
|
||||
const destinationTableColumnName =
|
||||
foreighKey.foreignKey?.destinationTableColumnName;
|
||||
const cascadeDelete = foreighKey.foreignKey?.cascadeDelete;
|
||||
const cascadeUpdate = foreighKey.foreignKey?.cascadeUpdate;
|
||||
const foreignKeyName = foreighKey.foreignKey?.foreignKeyName;
|
||||
|
||||
const comma = (() => {
|
||||
if (index === foreignKeys.length - 1) return "";
|
||||
|
||||
@@ -60,6 +60,9 @@ module.exports = async function updateTable({
|
||||
* @description Initial setup
|
||||
*/
|
||||
|
||||
/** @type {any[]} */
|
||||
let errorLogs = [];
|
||||
|
||||
/**
|
||||
* @description Initialize table info array. This value will be
|
||||
* changing depending on if a field is renamed or not.
|
||||
@@ -530,7 +533,7 @@ module.exports = async function updateTable({
|
||||
foreignKeyName,
|
||||
} = foreignKey;
|
||||
|
||||
const foreinKeyText = `ADD CONSTRAINT \`${foreignKeyName}\` FOREIGN KEY (${fieldName}) REFERENCES ${destinationTableName}(${destinationTableColumnName})${
|
||||
const foreinKeyText = `ADD CONSTRAINT \`${foreignKeyName}\` FOREIGN KEY (\`${fieldName}\`) REFERENCES \`${destinationTableName}\`(\`${destinationTableColumnName}\`)${
|
||||
cascadeDelete ? " ON DELETE CASCADE" : ""
|
||||
}${cascadeUpdate ? " ON UPDATE CASCADE" : ""}`;
|
||||
// const foreinKeyText = `ADD CONSTRAINT \`${foreignKeyName}\` FOREIGN KEY (${fieldName}) REFERENCES ${destinationTableName}(${destinationTableColumnName})${cascadeDelete ? " ON DELETE CASCADE" : ""}${cascadeUpdate ? " ON UPDATE CASCADE" : ""}` + ",";
|
||||
@@ -541,6 +544,10 @@ module.exports = async function updateTable({
|
||||
database: dbFullName,
|
||||
queryString: finalQueryString,
|
||||
});
|
||||
|
||||
if (!addForeignKey?.serverStatus) {
|
||||
errorLogs.push(addForeignKey);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user