Skip to content

Commit 780a1da

Browse files
committed
Merge branch 'alternation-engine' of https://github.com/drizzle-team/drizzle-orm into alternation-engine
2 parents 1592767 + 635addf commit 780a1da

File tree

4 files changed

+24
-57
lines changed

4 files changed

+24
-57
lines changed

.github/workflows/release-feature-branch.yaml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -273,31 +273,6 @@ jobs:
273273
*) echo "Unknown shard: ${{matrix.shard}}"; exit 1 ;;
274274
esac
275275
276-
- name: Stop DBs
277-
if: always() && ${{ matrix.dbs && join(matrix.dbs, ',') != '' }}
278-
shell: bash
279-
run: |
280-
set -euxo pipefail
281-
282-
if [ -n "${{ join(matrix.dbs, ' ') }}" ]; then
283-
compose_files=()
284-
for db in ${{ join(matrix.dbs, ' ') }}; do
285-
case "$db" in
286-
postgres) compose_files+=("-f" "compose/postgres.yml") ;;
287-
postgres-postgis) compose_files+=("-f" "compose/postgres-postgis.yml") ;;
288-
postgres-vector) compose_files+=("-f" "compose/postgres-vector.yml") ;;
289-
mysql) compose_files+=("-f" "compose/mysql.yml") ;;
290-
singlestore) compose_files+=("-f" "compose/singlestore.yml") ;;
291-
singlestore-many) compose_files+=("-f" "compose/singlestore-many.yml") ;;
292-
mssql) compose_files+=("-f" "compose/mssql.yml") ;;
293-
cockroach) compose_files+=("-f" "compose/cockroach.yml") ;;
294-
gel) compose_files+=("-f" "compose/gel.yml") ;;
295-
*) echo "Unknown db '$db'"; exit 1 ;;
296-
esac
297-
done
298-
docker compose "${compose_files[@]}" down -v
299-
fi
300-
301276
attw:
302277
needs: [prepare]
303278
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository

drizzle-kit/src/dialects/mysql/diff.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,11 @@ export const ddlDiff = async (
285285
).map((it) => prepareStatement('drop_index', { index: it }));
286286

287287
const dropFKStatements = fksDiff.filter((it) => it.$diffType === 'drop')
288-
.filter((it) => !deletedTables.some((x) => x.name === it.table))
288+
.filter((it) => {
289+
const tableDeteled = deletedTables.some((x) => x.name === it.table);
290+
const tableToDeleted = deletedTables.some((x) => x.name === it.tableTo);
291+
return !(tableDeteled && !tableToDeleted);
292+
})
289293
.map((it) => prepareStatement('drop_constraint', { table: it.table, constraint: it.name }));
290294

291295
const dropPKStatements = pksDiff.filter((it) => it.$diffType === 'drop')
@@ -440,6 +444,7 @@ export const ddlDiff = async (
440444

441445
const statements = [
442446
...createTableStatements,
447+
...dropFKStatements,
443448
...dropTableStatements,
444449
...renameTableStatements,
445450

@@ -450,16 +455,16 @@ export const ddlDiff = async (
450455
...alterViewStatements,
451456

452457
...dropCheckStatements,
453-
...dropFKStatements,
458+
454459
...dropIndexeStatements,
455460
...dropPKStatements,
456461

457462
...columnAlterStatements,
458463
...columnRecreateStatatements,
459464

465+
...addColumnsStatemets,
460466
...createPKStatements,
461467

462-
...addColumnsStatemets,
463468
...createIndexesStatements,
464469
...createFKsStatements,
465470
...createCheckStatements,

drizzle-kit/tests/mysql/constraints.test.ts

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -898,18 +898,10 @@ test('drop column with pk and add pk to another column #2', async () => {
898898
// https://github.com/drizzle-team/drizzle-orm/issues/4456
899899
test('drop column with pk and add pk to another column #3', async () => {
900900
const schema1 = {
901-
authors: mysqlTable(
902-
'authors',
903-
{
904-
publicationId: varchar('publication_id', { length: 64 }),
905-
authorID: varchar('author_id', { length: 10 }),
906-
},
907-
(table) => {
908-
return {
909-
pk: primaryKey(table.publicationId, table.authorID),
910-
};
911-
},
912-
),
901+
authors: mysqlTable('authors', {
902+
publicationId: varchar('publication_id', { length: 64 }),
903+
authorID: varchar('author_id', { length: 10 }),
904+
}, (table) => [primaryKey({ columns: [table.publicationId, table.authorID] })]),
913905
};
914906

915907
const { sqlStatements: st1, next: n1 } = await diff({}, schema1, []);
@@ -922,19 +914,13 @@ test('drop column with pk and add pk to another column #3', async () => {
922914
expect(pst1).toStrictEqual(expectedSt1);
923915

924916
const schema2 = {
925-
authors: mysqlTable(
926-
'authors',
927-
{
928-
publicationId: varchar('publication_id', { length: 64 }),
929-
authorID: varchar('author_id', { length: 10 }),
930-
orcidId: varchar('orcid_id', { length: 64 }),
931-
},
932-
(table) => {
933-
return {
934-
pk: primaryKey(table.publicationId, table.authorID, table.orcidId),
935-
};
936-
},
937-
),
917+
authors: mysqlTable('authors', {
918+
publicationId: varchar('publication_id', { length: 64 }),
919+
authorID: varchar('author_id', { length: 10 }),
920+
orcidId: varchar('orcid_id', { length: 64 }),
921+
}, (table) => [
922+
primaryKey({ columns: [table.publicationId, table.authorID, table.orcidId] }),
923+
]),
938924
};
939925

940926
const { sqlStatements: st2 } = await diff(n1, schema2, []);

drizzle-kit/tests/mysql/mysql.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ test('drop tables with fk constraint', async () => {
242242
const table1 = mysqlTable('table1', {
243243
column1: int().primaryKey(),
244244
});
245-
const table2 = mysqlTable('table1', {
245+
const table2 = mysqlTable('table2', {
246246
column1: int().primaryKey(),
247247
column2: int().references(() => table1.column1),
248248
});
@@ -252,8 +252,8 @@ test('drop tables with fk constraint', async () => {
252252
const { sqlStatements: pst1 } = await push({ db, to: schema1 });
253253
const expectedSt1 = [
254254
'CREATE TABLE `table1` (\n\t`column1` int PRIMARY KEY\n);\n',
255-
'CREATE TABLE `table2` (\n\t`column1` int PRIMARY KEY,\n\t`column2` int,'
256-
+ '\n\tCONSTRAINT `table1_column2_table1_column1_fkey` FOREIGN KEY (`column2`) REFERENCES `table1`(`column1`)\n);\n',
255+
'CREATE TABLE `table2` (\n\t`column1` int PRIMARY KEY,\n\t`column2` int\n);\n',
256+
'ALTER TABLE \`table2\` ADD CONSTRAINT `table2_column2_table1_column1_fkey` FOREIGN KEY (`column2`) REFERENCES `table1`(`column1`);',
257257
];
258258
expect(st1).toStrictEqual(expectedSt1);
259259
expect(pst1).toStrictEqual(expectedSt1);
@@ -262,8 +262,9 @@ test('drop tables with fk constraint', async () => {
262262
const { sqlStatements: pst2 } = await push({ db, to: {} });
263263

264264
const expectedSt2 = [
265-
'DROP TABLE `table2`;',
265+
'ALTER TABLE `table2` DROP CONSTRAINT `table2_column2_table1_column1_fkey`;',
266266
'DROP TABLE `table1`;',
267+
'DROP TABLE `table2`;',
267268
];
268269
expect(st2).toStrictEqual(expectedSt2);
269270
expect(pst2).toStrictEqual(expectedSt2);

0 commit comments

Comments
 (0)