Bugfix
This commit is contained in:
@@ -386,8 +386,6 @@ export default function sqlGenerator<
|
||||
|
||||
orderSrt += ` ${orderFields.join(", ")} ${genObject.order.strategy}`;
|
||||
|
||||
console.log("orderSrt", orderSrt);
|
||||
|
||||
queryString += ` ${orderSrt}`;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import fs from "fs";
|
||||
import createTable from "../utils/createTable";
|
||||
import updateTable from "../utils/updateTable";
|
||||
import { DSQL_DatabaseSchemaType } from "../../types";
|
||||
@@ -74,7 +73,9 @@ export default async function createDbFromSchema({
|
||||
|
||||
if (!dbCheck?.[0]?.dbFullName) {
|
||||
const newDatabase = await dbHandler({
|
||||
query: `CREATE DATABASE IF NOT EXISTS \`${dbFullName}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin`,
|
||||
query: `CREATE DATABASE IF NOT EXISTS \`${dbFullName}\` CHARACTER SET utf8mb4 COLLATE ${
|
||||
database.collation || "utf8mb4_bin"
|
||||
}`,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,9 @@ export default async function createTable({
|
||||
}
|
||||
|
||||
createTableQueryArray.push(
|
||||
`) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;`
|
||||
`) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=${
|
||||
tableSchema?.collation || "utf8mb4_bin"
|
||||
};`
|
||||
);
|
||||
|
||||
const createTableQuery = createTableQueryArray.join("\n");
|
||||
|
||||
@@ -92,6 +92,28 @@ export default async function updateTable({
|
||||
throw new Error("Recorded Table entry not found!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Table Default Collation
|
||||
*
|
||||
* @description Update Column Collation
|
||||
*/
|
||||
if (tableSchema.collation) {
|
||||
try {
|
||||
const existingCollation = (await dbHandler({
|
||||
query: `SHOW TABLE STATUS LIKE '${tableName}'`,
|
||||
config: { database: dbFullName },
|
||||
})) as any[];
|
||||
|
||||
const existingCollationStr = existingCollation?.[0].Collation;
|
||||
|
||||
if (existingCollationStr !== tableSchema.collation) {
|
||||
await dbHandler({
|
||||
query: `ALTER TABLE \`${dbFullName}\`.\`${tableName}\` CONVERT TO CHARACTER SET utf8mb4 COLLATE ${tableSchema.collation}`,
|
||||
});
|
||||
}
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Table updates
|
||||
*
|
||||
|
||||
@@ -128,6 +128,7 @@ export type DSQL_DATASQUIREL_USER_DATABASES = {
|
||||
active_clone_parent_db?: string;
|
||||
active_clone_parent_db_id?: number;
|
||||
active_data?: number;
|
||||
collation?: string;
|
||||
last_checked_date_code?: number;
|
||||
date_created?: string;
|
||||
date_created_code?: number;
|
||||
@@ -152,6 +153,7 @@ export type DSQL_DATASQUIREL_USER_DATABASE_TABLES = {
|
||||
child_table_parent_database_schema_id?: number;
|
||||
child_table_parent_table_schema_id?: number;
|
||||
active_data?: 0 | 1;
|
||||
collation?: string;
|
||||
last_checked_date_code?: number;
|
||||
date_created?: string;
|
||||
date_created_code?: number;
|
||||
|
||||
@@ -80,12 +80,18 @@ export interface DSQL_DatabaseSchemaType {
|
||||
childDatabase?: boolean;
|
||||
childDatabaseDbId?: string | number;
|
||||
updateData?: boolean;
|
||||
collation?: (typeof MariaDBCollations)[number];
|
||||
}
|
||||
|
||||
export interface DSQL_ChildrenDatabaseObject {
|
||||
dbId?: string | number;
|
||||
}
|
||||
|
||||
export const MariaDBCollations = [
|
||||
"utf8mb4_bin",
|
||||
"utf8mb4_unicode_520_ci",
|
||||
] as const;
|
||||
|
||||
export interface DSQL_TableSchemaType {
|
||||
id?: string | number;
|
||||
tableName: string;
|
||||
@@ -98,6 +104,7 @@ export interface DSQL_TableSchemaType {
|
||||
childTableId?: string | number;
|
||||
tableNameOld?: string;
|
||||
childTableDbId?: string | number;
|
||||
collation?: (typeof MariaDBCollations)[number];
|
||||
}
|
||||
|
||||
export interface DSQL_ChildrenTablesType {
|
||||
|
||||
Reference in New Issue
Block a user