CS
CS
Explore posts from servers
DTDrizzle Team
Created by CS on 3/24/2024 in #help
What am I doing wrong with migrations?
Ah found it in another answer here from last year: define the callback in a references function as AnyMySqlColumn
19 replies
DTDrizzle Team
Created by CS on 3/24/2024 in #help
What am I doing wrong with migrations?
No description
19 replies
DTDrizzle Team
Created by CS on 3/24/2024 in #help
What am I doing wrong with migrations?
Ok I think I fixed my problem, it was something stupid from my side... (a small typo basically)
19 replies
DTDrizzle Team
Created by CS on 3/24/2024 in #help
What am I doing wrong with migrations?
But I have no clue why this is happening in my update query
19 replies
DTDrizzle Team
Created by CS on 3/24/2024 in #help
What am I doing wrong with migrations?
At the part where it's trying to access col.name apparently
19 replies
DTDrizzle Team
Created by CS on 3/24/2024 in #help
What am I doing wrong with migrations?
The error seems to stem from this part though:
buildUpdateSet(table: MySqlTable, set: UpdateSet): SQL {
const tableColumns = table[Table.Symbol.Columns];

const columnNames = Object.keys(tableColumns).filter((colName) =>
set[colName] !== undefined || tableColumns[colName]?.onUpdateFn !== undefined
);

const setSize = columnNames.length;
return sql.join(columnNames.flatMap((colName, i) => {
const col = tableColumns[colName]!;

const value = set[colName] ?? sql.param(col.onUpdateFn!(), col);
const res = sql`${sql.identifier(col.name)} = ${value}`;

if (i < setSize - 1) {
return [res, sql.raw(', ')];
}
return [res];
}));
}
buildUpdateSet(table: MySqlTable, set: UpdateSet): SQL {
const tableColumns = table[Table.Symbol.Columns];

const columnNames = Object.keys(tableColumns).filter((colName) =>
set[colName] !== undefined || tableColumns[colName]?.onUpdateFn !== undefined
);

const setSize = columnNames.length;
return sql.join(columnNames.flatMap((colName, i) => {
const col = tableColumns[colName]!;

const value = set[colName] ?? sql.param(col.onUpdateFn!(), col);
const res = sql`${sql.identifier(col.name)} = ${value}`;

if (i < setSize - 1) {
return [res, sql.raw(', ')];
}
return [res];
}));
}
19 replies
DTDrizzle Team
Created by CS on 3/24/2024 in #help
What am I doing wrong with migrations?
I think the console logs with file locations aren't that important, since it's obviously finding those files
19 replies
DTDrizzle Team
Created by CS on 3/24/2024 in #help
What am I doing wrong with migrations?
Using npm
19 replies
DTDrizzle Team
Created by CS on 3/24/2024 in #help
What am I doing wrong with migrations?
No description
19 replies
DTDrizzle Team
Created by CS on 3/24/2024 in #help
What am I doing wrong with migrations?
I just noticed something even more weird, when trying to bugfix one of my queries
19 replies
DTDrizzle Team
Created by CS on 3/24/2024 in #help
What am I doing wrong with migrations?
So far, it has only helped to reset the DB, run drizzle-kit generate, and then it worked again. I think our understanding of the migration part might be wrong. I'd be glad to receive any tips on how to properly handle this! Thanks in advance 👋
19 replies
DTDrizzle Team
Created by CS on 3/24/2024 in #help
What am I doing wrong with migrations?
No description
19 replies
DTDrizzle Team
Created by CS on 3/24/2024 in #help
What am I doing wrong with migrations?
When it reaches the migrate line though, it seems to fail:
C:\Users\CS\Documents\Code\API\node_modules\mysql2\promise.js:94
const localErr = new Error();
^
Error: Table 'card_type' already exists
at PromiseConnection.query (C:\Users\CS\Documents\Code\API\node_modules\mysql2\promise.js:94:22)
at MySql2PreparedQuery.execute (C:\Users\CS\Documents\Code\API\node_modules\src\mysql2\session.ts:85:18)
at MySql2Session.execute (C:\Users\CS\Documents\Code\API\node_modules\src\mysql-core\session.ts:81:5)
at MySql2Transaction.execute (C:\Users\CS\Documents\Code\API\node_modules\src\mysql-core\db.ts:335:23)
at C:\Users\CS\Documents\Code\API\node_modules\src\mysql-core\dialect.ts:58:16
at MySql2Session.transaction (C:\Users\CS\Documents\Code\API\node_modules\src\mysql2\session.ts:242:25)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at MySqlDialect.migrate (C:\Users\CS\Documents\Code\API\node_modules\src\mysql-core\dialect.ts:51:3)
at migrate (C:\Users\CS\Documents\Code\API\node_modules\src\mysql2\migrator.ts:10:2)
at initializeDatabase (C:\Users\CS\Documents\Code\API\src\db.ts:20:5)
C:\Users\CS\Documents\Code\API\node_modules\mysql2\promise.js:94
const localErr = new Error();
^
Error: Table 'card_type' already exists
at PromiseConnection.query (C:\Users\CS\Documents\Code\API\node_modules\mysql2\promise.js:94:22)
at MySql2PreparedQuery.execute (C:\Users\CS\Documents\Code\API\node_modules\src\mysql2\session.ts:85:18)
at MySql2Session.execute (C:\Users\CS\Documents\Code\API\node_modules\src\mysql-core\session.ts:81:5)
at MySql2Transaction.execute (C:\Users\CS\Documents\Code\API\node_modules\src\mysql-core\db.ts:335:23)
at C:\Users\CS\Documents\Code\API\node_modules\src\mysql-core\dialect.ts:58:16
at MySql2Session.transaction (C:\Users\CS\Documents\Code\API\node_modules\src\mysql2\session.ts:242:25)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at MySqlDialect.migrate (C:\Users\CS\Documents\Code\API\node_modules\src\mysql-core\dialect.ts:51:3)
at migrate (C:\Users\CS\Documents\Code\API\node_modules\src\mysql2\migrator.ts:10:2)
at initializeDatabase (C:\Users\CS\Documents\Code\API\src\db.ts:20:5)
19 replies