Skip to content

Commit 5eff1cc

Browse files
authored
Fix/branch clean up for pr integration tests (#31)
* branch clean up for pr * wip [last visited drizzle-kit/src/cli/validations/common.ts * wip [last visited drizzle-kit/src/schemaValidator.ts * drizzle kit cleaning * lint fix * remove unecessary readme.md * lint fix * integration-tests cleaning
1 parent d0fb8cd commit 5eff1cc

File tree

10 files changed

+281
-840
lines changed

10 files changed

+281
-840
lines changed

drizzle-kit/src/cli/schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import chalk from 'chalk';
22
import { checkHandler } from './commands/check';
33
import { assertOrmCoreVersion, assertPackages, assertStudioNodeVersion, ormVersionGt } from './utils';
44
import '../@types/utils';
5+
import { assertUnreachable } from '../global';
6+
import { type Setup } from '../serializer/studio';
57
import { assertV1OutFolder } from '../utils';
68
import { dropMigration } from './commands/drop';
79
import { upMysqlHandler } from './commands/mysqlUp';

integration-tests/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"license": "Apache-2.0",
1616
"private": true,
1717
"devDependencies": {
18-
"@libsql/client": "^0.10.0",
1918
"@neondatabase/serverless": "0.9.0",
2019
"@originjs/vite-plugin-commonjs": "^1.0.3",
2120
"@paralleldrive/cuid2": "^2.2.2",
@@ -42,7 +41,7 @@
4241
"@aws-sdk/client-rds-data": "^3.549.0",
4342
"@aws-sdk/credential-providers": "^3.549.0",
4443
"@electric-sql/pglite": "^0.1.1",
45-
"@libsql/client": "^0.10.0",
44+
"@libsql/client": "^0.5.6",
4645
"@miniflare/d1": "^2.14.2",
4746
"@miniflare/shared": "^2.14.2",
4847
"@planetscale/database": "^1.16.0",

integration-tests/tests/mysql/mysql-common.ts

Lines changed: 18 additions & 226 deletions
Original file line numberDiff line numberDiff line change
@@ -3577,237 +3577,29 @@ export function tests(driver?: string) {
35773577

35783578
await db.execute(sql`drop view ${newYorkers1}`);
35793579
});
3580+
});
35803581

3581-
test('$count separate', async (ctx) => {
3582-
const { db } = ctx.mysql;
3583-
3584-
const countTestTable = mysqlTable('count_test', {
3585-
id: int('id').notNull(),
3586-
name: text('name').notNull(),
3587-
});
3588-
3589-
await db.execute(sql`drop table if exists ${countTestTable}`);
3590-
await db.execute(sql`create table ${countTestTable} (id int, name text)`);
3591-
3592-
await db.insert(countTestTable).values([
3593-
{ id: 1, name: 'First' },
3594-
{ id: 2, name: 'Second' },
3595-
{ id: 3, name: 'Third' },
3596-
{ id: 4, name: 'Fourth' },
3597-
]);
3598-
3599-
const count = await db.$count(countTestTable);
3600-
3601-
await db.execute(sql`drop table ${countTestTable}`);
3602-
3603-
expect(count).toStrictEqual(4);
3604-
});
3605-
3606-
test('$count embedded', async (ctx) => {
3607-
const { db } = ctx.mysql;
3608-
3609-
const countTestTable = mysqlTable('count_test', {
3610-
id: int('id').notNull(),
3611-
name: text('name').notNull(),
3612-
});
3613-
3614-
await db.execute(sql`drop table if exists ${countTestTable}`);
3615-
await db.execute(sql`create table ${countTestTable} (id int, name text)`);
3616-
3617-
await db.insert(countTestTable).values([
3618-
{ id: 1, name: 'First' },
3619-
{ id: 2, name: 'Second' },
3620-
{ id: 3, name: 'Third' },
3621-
{ id: 4, name: 'Fourth' },
3622-
]);
3623-
3624-
const count = await db.select({
3625-
count: db.$count(countTestTable),
3626-
}).from(countTestTable);
3627-
3628-
await db.execute(sql`drop table ${countTestTable}`);
3629-
3630-
expect(count).toStrictEqual([
3631-
{ count: 4 },
3632-
{ count: 4 },
3633-
{ count: 4 },
3634-
{ count: 4 },
3635-
]);
3636-
});
3637-
3638-
test('$count separate reuse', async (ctx) => {
3639-
const { db } = ctx.mysql;
3640-
3641-
const countTestTable = mysqlTable('count_test', {
3642-
id: int('id').notNull(),
3643-
name: text('name').notNull(),
3644-
});
3645-
3646-
await db.execute(sql`drop table if exists ${countTestTable}`);
3647-
await db.execute(sql`create table ${countTestTable} (id int, name text)`);
3648-
3649-
await db.insert(countTestTable).values([
3650-
{ id: 1, name: 'First' },
3651-
{ id: 2, name: 'Second' },
3652-
{ id: 3, name: 'Third' },
3653-
{ id: 4, name: 'Fourth' },
3654-
]);
3655-
3656-
const count = db.$count(countTestTable);
3657-
3658-
const count1 = await count;
3659-
3660-
await db.insert(countTestTable).values({ id: 5, name: 'fifth' });
3661-
3662-
const count2 = await count;
3663-
3664-
await db.insert(countTestTable).values({ id: 6, name: 'sixth' });
3665-
3666-
const count3 = await count;
3667-
3668-
await db.execute(sql`drop table ${countTestTable}`);
3669-
3670-
expect(count1).toStrictEqual(4);
3671-
expect(count2).toStrictEqual(5);
3672-
expect(count3).toStrictEqual(6);
3673-
});
3674-
3675-
test('$count embedded reuse', async (ctx) => {
3676-
const { db } = ctx.mysql;
3677-
3678-
const countTestTable = mysqlTable('count_test', {
3679-
id: int('id').notNull(),
3680-
name: text('name').notNull(),
3681-
});
3682-
3683-
await db.execute(sql`drop table if exists ${countTestTable}`);
3684-
await db.execute(sql`create table ${countTestTable} (id int, name text)`);
3685-
3686-
await db.insert(countTestTable).values([
3687-
{ id: 1, name: 'First' },
3688-
{ id: 2, name: 'Second' },
3689-
{ id: 3, name: 'Third' },
3690-
{ id: 4, name: 'Fourth' },
3691-
]);
3692-
3693-
const count = db.select({
3694-
count: db.$count(countTestTable),
3695-
}).from(countTestTable);
3696-
3697-
const count1 = await count;
3698-
3699-
await db.insert(countTestTable).values({ id: 5, name: 'fifth' });
3700-
3701-
const count2 = await count;
3702-
3703-
await db.insert(countTestTable).values({ id: 6, name: 'sixth' });
3704-
3705-
const count3 = await count;
3706-
3707-
await db.execute(sql`drop table ${countTestTable}`);
3708-
3709-
expect(count1).toStrictEqual([
3710-
{ count: 4 },
3711-
{ count: 4 },
3712-
{ count: 4 },
3713-
{ count: 4 },
3714-
]);
3715-
expect(count2).toStrictEqual([
3716-
{ count: 5 },
3717-
{ count: 5 },
3718-
{ count: 5 },
3719-
{ count: 5 },
3720-
{ count: 5 },
3721-
]);
3722-
expect(count3).toStrictEqual([
3723-
{ count: 6 },
3724-
{ count: 6 },
3725-
{ count: 6 },
3726-
{ count: 6 },
3727-
{ count: 6 },
3728-
{ count: 6 },
3729-
]);
3730-
});
3731-
3732-
test('$count separate with filters', async (ctx) => {
3733-
const { db } = ctx.mysql;
3734-
3735-
const countTestTable = mysqlTable('count_test', {
3736-
id: int('id').notNull(),
3737-
name: text('name').notNull(),
3738-
});
3739-
3740-
await db.execute(sql`drop table if exists ${countTestTable}`);
3741-
await db.execute(sql`create table ${countTestTable} (id int, name text)`);
3742-
3743-
await db.insert(countTestTable).values([
3744-
{ id: 1, name: 'First' },
3745-
{ id: 2, name: 'Second' },
3746-
{ id: 3, name: 'Third' },
3747-
{ id: 4, name: 'Fourth' },
3748-
]);
3749-
3750-
const count = await db.$count(countTestTable, gt(countTestTable.id, 1));
3751-
3752-
await db.execute(sql`drop table ${countTestTable}`);
3753-
3754-
expect(count).toStrictEqual(3);
3755-
});
3756-
3757-
test('$count embedded with filters', async (ctx) => {
3758-
const { db } = ctx.mysql;
3759-
3760-
const countTestTable = mysqlTable('count_test', {
3761-
id: int('id').notNull(),
3762-
name: text('name').notNull(),
3763-
});
3764-
3765-
await db.execute(sql`drop table if exists ${countTestTable}`);
3766-
await db.execute(sql`create table ${countTestTable} (id int, name text)`);
3767-
3768-
await db.insert(countTestTable).values([
3769-
{ id: 1, name: 'First' },
3770-
{ id: 2, name: 'Second' },
3771-
{ id: 3, name: 'Third' },
3772-
{ id: 4, name: 'Fourth' },
3773-
]);
3774-
3775-
const count = await db.select({
3776-
count: db.$count(countTestTable, gt(countTestTable.id, 1)),
3777-
}).from(countTestTable);
3778-
3779-
await db.execute(sql`drop table ${countTestTable}`);
3780-
3781-
expect(count).toStrictEqual([
3782-
{ count: 3 },
3783-
{ count: 3 },
3784-
{ count: 3 },
3785-
{ count: 3 },
3786-
]);
3787-
});
3788-
3789-
test('limit 0', async (ctx) => {
3790-
const { db } = ctx.mysql;
3582+
test('limit 0', async (ctx) => {
3583+
const { db } = ctx.mysql;
37913584

3792-
await db.insert(usersTable).values({ name: 'John' });
3793-
const users = await db
3794-
.select()
3795-
.from(usersTable)
3796-
.limit(0);
3585+
await db.insert(usersTable).values({ name: 'John' });
3586+
const users = await db
3587+
.select()
3588+
.from(usersTable)
3589+
.limit(0);
37973590

3798-
expect(users).toEqual([]);
3799-
});
3591+
expect(users).toEqual([]);
3592+
});
38003593

3801-
test('limit -1', async (ctx) => {
3802-
const { db } = ctx.mysql;
3594+
test('limit -1', async (ctx) => {
3595+
const { db } = ctx.mysql;
38033596

3804-
await db.insert(usersTable).values({ name: 'John' });
3805-
const users = await db
3806-
.select()
3807-
.from(usersTable)
3808-
.limit(-1);
3597+
await db.insert(usersTable).values({ name: 'John' });
3598+
const users = await db
3599+
.select()
3600+
.from(usersTable)
3601+
.limit(-1);
38093602

3810-
expect(users.length).toBeGreaterThan(0);
3811-
});
3603+
expect(users.length).toBeGreaterThan(0);
38123604
});
38133605
}

integration-tests/tests/pg/awsdatapi.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -799,18 +799,19 @@ test('migrator : default migration strategy', async () => {
799799
});
800800

801801
test('migrator : migrate with custom schema', async () => {
802+
const customSchema = randomString();
802803
await db.execute(sql`drop table if exists all_columns`);
803804
await db.execute(sql`drop table if exists users12`);
804805
await db.execute(sql`drop table if exists "drizzle"."__drizzle_migrations"`);
805806

806807
await migrate(db, {
807808
migrationsFolder: './drizzle2/pg',
808-
migrationsSchema: 'custom_migrations',
809+
migrationsSchema: customSchema,
809810
});
810811

811812
// test if the custom migrations table was created
812813
const { rows } = await db.execute(
813-
sql`select * from custom_migrations."__drizzle_migrations";`,
814+
sql`select * from ${sql.identifier(customSchema)}."__drizzle_migrations";`,
814815
);
815816
expect(rows).toBeTruthy();
816817
expect(rows!.length).toBeGreaterThan(0);
@@ -823,7 +824,7 @@ test('migrator : migrate with custom schema', async () => {
823824
await db.execute(sql`drop table all_columns`);
824825
await db.execute(sql`drop table users12`);
825826
await db.execute(
826-
sql`drop table custom_migrations."__drizzle_migrations"`,
827+
sql`drop table ${sql.identifier(customSchema)}."__drizzle_migrations"`,
827828
);
828829
});
829830

@@ -857,19 +858,20 @@ test('migrator : migrate with custom table', async () => {
857858

858859
test('migrator : migrate with custom table and custom schema', async () => {
859860
const customTable = randomString();
861+
const customSchema = randomString();
860862
await db.execute(sql`drop table if exists all_columns`);
861863
await db.execute(sql`drop table if exists users12`);
862864
await db.execute(sql`drop table if exists "drizzle"."__drizzle_migrations"`);
863865

864866
await migrate(db, {
865867
migrationsFolder: './drizzle2/pg',
866868
migrationsTable: customTable,
867-
migrationsSchema: 'custom_migrations',
869+
migrationsSchema: customSchema,
868870
});
869871

870872
// test if the custom migrations table was created
871873
const { rows } = await db.execute(
872-
sql`select * from custom_migrations.${
874+
sql`select * from ${sql.identifier(customSchema)}.${
873875
sql.identifier(
874876
customTable,
875877
)
@@ -886,7 +888,7 @@ test('migrator : migrate with custom table and custom schema', async () => {
886888
await db.execute(sql`drop table all_columns`);
887889
await db.execute(sql`drop table users12`);
888890
await db.execute(
889-
sql`drop table custom_migrations.${
891+
sql`drop table ${sql.identifier(customSchema)}.${
890892
sql.identifier(
891893
customTable,
892894
)

0 commit comments

Comments
 (0)