Skip to content

Commit

Permalink
Initial tests for the mysql dot name bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rathboma committed Apr 26, 2024
1 parent 72dfae6 commit d63e390
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/studio/tests/integration/lib/db/clients/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export function runCommonTests(getUtil, opts = {}) {
test("Should generate scripts for top selection", async () => {
await getUtil().buildSelectTopQueryTests()
})

test("Is (not) null filter", async () => {
await getUtil().buildIsNullTests()
})
Expand Down
11 changes: 11 additions & 0 deletions apps/studio/tests/integration/lib/db/clients/mysql.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,15 @@ function testWith(tag, socket = false, readonly = false) {
SELECT id, name, email, status FROM user limit 10;
END
`

const dotTableCreator = "CREATE TABLE `foo.bar`(id integer, name varchar(255))"
const dotInsert = "INSERT INTO `foo.bar`(id, name) values(1, 'Dot McDot')"
await util.knex.schema.raw(functionDDL)
await util.knex.schema.raw(routine1DDL)
await util.knex.schema.raw(routine2DDL)
await util.knex.schema.raw("CREATE TABLE bittable(id int, bitcol bit NOT NULL)");
await util.knex.schema.raw(dotTableCreator);
await util.knex.schema.raw(dotInsert);
})

afterAll(async () => {
Expand All @@ -104,6 +109,12 @@ function testWith(tag, socket = false, readonly = false) {
}
})

it.only("Should work properly with tables that have dots in them", async () => {
const r = await util.connection.selectTop("foo.bar", 0, 10, [{field: 'id', dir: 'ASC'}])
const result = r.result.map((r) => r.name || r.NAME)
expect(result).toMatchObject(['Dot McDot'])
})

it("Should fetch routines correctly", async () => {
const routines = await util.connection.listRoutines()
expect(routines.length).toBe(3)
Expand Down
11 changes: 11 additions & 0 deletions apps/studio/tests/integration/lib/db/clients/sqlite.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ describe("Sqlite Tests", () => {
{ id: 2, flag: 0 },
{ id: 3, flag: 0 },
])
const dotTableCreator = "CREATE TABLE `foo.bar`(id integer, name varchar(255))"
const dotInsert = "INSERT INTO `foo.bar`(id, name) values(1, 'Dot McDot')"

await util.knex.schema.raw(dotTableCreator);
await util.knex.schema.raw(dotInsert);
})

afterAll(async () => {
Expand Down Expand Up @@ -61,6 +66,12 @@ describe("Sqlite Tests", () => {
}).not.toThrowError()
})

it.only("Should work properly with tables that have dots in them", async () => {
const r = await util.connection.selectTop("foo.bar", 0, 10, [{ field: 'id', dir: 'ASC' }], this.defaultSchema)
const result = r.result.map((r) => r.name || r.NAME)
expect(result).toMatchObject(['Dot McDot'])
})

it("Should apply changes to boolean values correctly", async () => {
const updates = [
{ id: 1, expect: false, toBe: 0 },
Expand Down
24 changes: 24 additions & 0 deletions apps/studio/tests/lib/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ export class DBTestUtil {
this.personId = isOracle ? Number(people[0].id) : people[0].id
await this.knex("people_jobs").insert({job_id: this.jobId, person_id: this.personId })

// See createTables for why this is commented out
// await this.knex("foo.bar").insert({ id: 1, name: "Dots are evil" });


if (!this.options.skipGeneratedColumns) {
await this.knex('with_generated_cols').insert([
{ id: 1, first_name: 'Tom', last_name: 'Tester' },
Expand Down Expand Up @@ -345,6 +349,15 @@ export class DBTestUtil {
expect(groupColumns.length).toBe(2)
}


async testDotTable() {
// FIXME: Make this generic to all tables.
// see 'createTables' for why this is commented out
// const r = await this.connection.selectTop("foo.bar", 0, 10, [{field: 'id', dir: 'ASC'}], this.defaultSchema)
// const result = r.result.map((r: any) => r.name || r.NAME)
// expect(result).toMatchObject(['Dots are evil'])
}

/**
* Tests related to the table view
* fetching PK, selecting data, etc.
Expand All @@ -366,6 +379,7 @@ export class DBTestUtil {
await this.knex("group_table").insert({select_col: "bar"})
await this.knex("group_table").insert({select_col: "abc"})


let r = await this.connection.selectTop("group_table", 0, 10, [{field: "select_col", dir: 'ASC'}], [], this.defaultSchema)
let result = r.result.map((r: any) => r.select_col || r.SELECT_COL)
expect(result).toMatchObject(["abc", "bar"])
Expand All @@ -386,6 +400,8 @@ export class DBTestUtil {
result = r.result.map((r: any) => r.bananas || r.BANANAS)
expect(result).toMatchObject(["pears"])

await this.testDotTable()

await this.knex("group_table").where({select_col: "bar"}).delete()
await this.knex("group_table").where({select_col: "abc"}).delete()
}
Expand Down Expand Up @@ -1056,6 +1072,14 @@ export class DBTestUtil {
table.string("country").notNullable()
})

// FIXME: Knex doesn't support tables with dots in the name
// https://github.com/knex/knex/issues/2762
// Should be used in the dot table tests
// await this.knex.schema.createTable(knex.raw('`foo.bar`'), (table) => {
// table.integer('id')
// table.string('name')
// })

await this.knex.schema.createTable('MixedCase', (table) => {
primary(table)
table.string("bananas")
Expand Down

0 comments on commit d63e390

Please sign in to comment.