This commit is contained in:
Benjamin Toby
2024-12-08 09:58:57 +01:00
parent 8a8257d17e
commit 7bd4b2fe65
76 changed files with 1783 additions and 1106 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
export = createDbFromSchema;
/**
* Create database from Schema Function
* ==============================================================================
* =============================================
* @param {object} params - Single object params
* @param {number|string|null} [params.userId] - User ID or null
* @param {string} [params.targetDatabase] - User Database full name
+1 -1
View File
@@ -16,7 +16,7 @@ const execFlag = process.argv.find((arg) => arg === "--exec");
/**
* Create database from Schema Function
* ==============================================================================
* =============================================
* @param {object} params - Single object params
* @param {number|string|null} [params.userId] - User ID or null
* @param {string} [params.targetDatabase] - User Database full name
+11 -10
View File
@@ -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 "";
+8 -1
View File
@@ -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);
}
}
////////////////////////////////////////