Skip to content

Commit

Permalink
Fix/branch clean up for pr integration tests (#31)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Rodriguespn authored Oct 1, 2024
1 parent d0fb8cd commit 5eff1cc
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 840 deletions.
2 changes: 2 additions & 0 deletions drizzle-kit/src/cli/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import chalk from 'chalk';
import { checkHandler } from './commands/check';
import { assertOrmCoreVersion, assertPackages, assertStudioNodeVersion, ormVersionGt } from './utils';
import '../@types/utils';
import { assertUnreachable } from '../global';
import { type Setup } from '../serializer/studio';
import { assertV1OutFolder } from '../utils';
import { dropMigration } from './commands/drop';
import { upMysqlHandler } from './commands/mysqlUp';
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"license": "Apache-2.0",
"private": true,
"devDependencies": {
"@libsql/client": "^0.10.0",
"@neondatabase/serverless": "0.9.0",
"@originjs/vite-plugin-commonjs": "^1.0.3",
"@paralleldrive/cuid2": "^2.2.2",
Expand All @@ -42,7 +41,7 @@
"@aws-sdk/client-rds-data": "^3.549.0",
"@aws-sdk/credential-providers": "^3.549.0",
"@electric-sql/pglite": "^0.1.1",
"@libsql/client": "^0.10.0",
"@libsql/client": "^0.5.6",
"@miniflare/d1": "^2.14.2",
"@miniflare/shared": "^2.14.2",
"@planetscale/database": "^1.16.0",
Expand Down
244 changes: 18 additions & 226 deletions integration-tests/tests/mysql/mysql-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3577,237 +3577,29 @@ export function tests(driver?: string) {

await db.execute(sql`drop view ${newYorkers1}`);
});
});

test('$count separate', async (ctx) => {
const { db } = ctx.mysql;

const countTestTable = mysqlTable('count_test', {
id: int('id').notNull(),
name: text('name').notNull(),
});

await db.execute(sql`drop table if exists ${countTestTable}`);
await db.execute(sql`create table ${countTestTable} (id int, name text)`);

await db.insert(countTestTable).values([
{ id: 1, name: 'First' },
{ id: 2, name: 'Second' },
{ id: 3, name: 'Third' },
{ id: 4, name: 'Fourth' },
]);

const count = await db.$count(countTestTable);

await db.execute(sql`drop table ${countTestTable}`);

expect(count).toStrictEqual(4);
});

test('$count embedded', async (ctx) => {
const { db } = ctx.mysql;

const countTestTable = mysqlTable('count_test', {
id: int('id').notNull(),
name: text('name').notNull(),
});

await db.execute(sql`drop table if exists ${countTestTable}`);
await db.execute(sql`create table ${countTestTable} (id int, name text)`);

await db.insert(countTestTable).values([
{ id: 1, name: 'First' },
{ id: 2, name: 'Second' },
{ id: 3, name: 'Third' },
{ id: 4, name: 'Fourth' },
]);

const count = await db.select({
count: db.$count(countTestTable),
}).from(countTestTable);

await db.execute(sql`drop table ${countTestTable}`);

expect(count).toStrictEqual([
{ count: 4 },
{ count: 4 },
{ count: 4 },
{ count: 4 },
]);
});

test('$count separate reuse', async (ctx) => {
const { db } = ctx.mysql;

const countTestTable = mysqlTable('count_test', {
id: int('id').notNull(),
name: text('name').notNull(),
});

await db.execute(sql`drop table if exists ${countTestTable}`);
await db.execute(sql`create table ${countTestTable} (id int, name text)`);

await db.insert(countTestTable).values([
{ id: 1, name: 'First' },
{ id: 2, name: 'Second' },
{ id: 3, name: 'Third' },
{ id: 4, name: 'Fourth' },
]);

const count = db.$count(countTestTable);

const count1 = await count;

await db.insert(countTestTable).values({ id: 5, name: 'fifth' });

const count2 = await count;

await db.insert(countTestTable).values({ id: 6, name: 'sixth' });

const count3 = await count;

await db.execute(sql`drop table ${countTestTable}`);

expect(count1).toStrictEqual(4);
expect(count2).toStrictEqual(5);
expect(count3).toStrictEqual(6);
});

test('$count embedded reuse', async (ctx) => {
const { db } = ctx.mysql;

const countTestTable = mysqlTable('count_test', {
id: int('id').notNull(),
name: text('name').notNull(),
});

await db.execute(sql`drop table if exists ${countTestTable}`);
await db.execute(sql`create table ${countTestTable} (id int, name text)`);

await db.insert(countTestTable).values([
{ id: 1, name: 'First' },
{ id: 2, name: 'Second' },
{ id: 3, name: 'Third' },
{ id: 4, name: 'Fourth' },
]);

const count = db.select({
count: db.$count(countTestTable),
}).from(countTestTable);

const count1 = await count;

await db.insert(countTestTable).values({ id: 5, name: 'fifth' });

const count2 = await count;

await db.insert(countTestTable).values({ id: 6, name: 'sixth' });

const count3 = await count;

await db.execute(sql`drop table ${countTestTable}`);

expect(count1).toStrictEqual([
{ count: 4 },
{ count: 4 },
{ count: 4 },
{ count: 4 },
]);
expect(count2).toStrictEqual([
{ count: 5 },
{ count: 5 },
{ count: 5 },
{ count: 5 },
{ count: 5 },
]);
expect(count3).toStrictEqual([
{ count: 6 },
{ count: 6 },
{ count: 6 },
{ count: 6 },
{ count: 6 },
{ count: 6 },
]);
});

test('$count separate with filters', async (ctx) => {
const { db } = ctx.mysql;

const countTestTable = mysqlTable('count_test', {
id: int('id').notNull(),
name: text('name').notNull(),
});

await db.execute(sql`drop table if exists ${countTestTable}`);
await db.execute(sql`create table ${countTestTable} (id int, name text)`);

await db.insert(countTestTable).values([
{ id: 1, name: 'First' },
{ id: 2, name: 'Second' },
{ id: 3, name: 'Third' },
{ id: 4, name: 'Fourth' },
]);

const count = await db.$count(countTestTable, gt(countTestTable.id, 1));

await db.execute(sql`drop table ${countTestTable}`);

expect(count).toStrictEqual(3);
});

test('$count embedded with filters', async (ctx) => {
const { db } = ctx.mysql;

const countTestTable = mysqlTable('count_test', {
id: int('id').notNull(),
name: text('name').notNull(),
});

await db.execute(sql`drop table if exists ${countTestTable}`);
await db.execute(sql`create table ${countTestTable} (id int, name text)`);

await db.insert(countTestTable).values([
{ id: 1, name: 'First' },
{ id: 2, name: 'Second' },
{ id: 3, name: 'Third' },
{ id: 4, name: 'Fourth' },
]);

const count = await db.select({
count: db.$count(countTestTable, gt(countTestTable.id, 1)),
}).from(countTestTable);

await db.execute(sql`drop table ${countTestTable}`);

expect(count).toStrictEqual([
{ count: 3 },
{ count: 3 },
{ count: 3 },
{ count: 3 },
]);
});

test('limit 0', async (ctx) => {
const { db } = ctx.mysql;
test('limit 0', async (ctx) => {
const { db } = ctx.mysql;

await db.insert(usersTable).values({ name: 'John' });
const users = await db
.select()
.from(usersTable)
.limit(0);
await db.insert(usersTable).values({ name: 'John' });
const users = await db
.select()
.from(usersTable)
.limit(0);

expect(users).toEqual([]);
});
expect(users).toEqual([]);
});

test('limit -1', async (ctx) => {
const { db } = ctx.mysql;
test('limit -1', async (ctx) => {
const { db } = ctx.mysql;

await db.insert(usersTable).values({ name: 'John' });
const users = await db
.select()
.from(usersTable)
.limit(-1);
await db.insert(usersTable).values({ name: 'John' });
const users = await db
.select()
.from(usersTable)
.limit(-1);

expect(users.length).toBeGreaterThan(0);
});
expect(users.length).toBeGreaterThan(0);
});
}
14 changes: 8 additions & 6 deletions integration-tests/tests/pg/awsdatapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -799,18 +799,19 @@ test('migrator : default migration strategy', async () => {
});

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

await migrate(db, {
migrationsFolder: './drizzle2/pg',
migrationsSchema: 'custom_migrations',
migrationsSchema: customSchema,
});

// test if the custom migrations table was created
const { rows } = await db.execute(
sql`select * from custom_migrations."__drizzle_migrations";`,
sql`select * from ${sql.identifier(customSchema)}."__drizzle_migrations";`,
);
expect(rows).toBeTruthy();
expect(rows!.length).toBeGreaterThan(0);
Expand All @@ -823,7 +824,7 @@ test('migrator : migrate with custom schema', async () => {
await db.execute(sql`drop table all_columns`);
await db.execute(sql`drop table users12`);
await db.execute(
sql`drop table custom_migrations."__drizzle_migrations"`,
sql`drop table ${sql.identifier(customSchema)}."__drizzle_migrations"`,
);
});

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

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

await migrate(db, {
migrationsFolder: './drizzle2/pg',
migrationsTable: customTable,
migrationsSchema: 'custom_migrations',
migrationsSchema: customSchema,
});

// test if the custom migrations table was created
const { rows } = await db.execute(
sql`select * from custom_migrations.${
sql`select * from ${sql.identifier(customSchema)}.${
sql.identifier(
customTable,
)
Expand All @@ -886,7 +888,7 @@ test('migrator : migrate with custom table and custom schema', async () => {
await db.execute(sql`drop table all_columns`);
await db.execute(sql`drop table users12`);
await db.execute(
sql`drop table custom_migrations.${
sql`drop table ${sql.identifier(customSchema)}.${
sql.identifier(
customTable,
)
Expand Down
Loading

0 comments on commit 5eff1cc

Please sign in to comment.