Skip to content

Commit

Permalink
fixes for primary key indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
rathboma committed Jun 20, 2022
1 parent a5fdf6c commit 6654ca6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 22 deletions.
3 changes: 2 additions & 1 deletion apps/studio/src/lib/db/clients/postgresql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,8 @@ async function listCockroachIndexes(conn: Conn, table: string, schema: string):
name: indexName,
table: table,
schema: schema,
primary: first.index_name === 'primary',
// v21.2 onwards changes index names for primary keys
primary: first.index_name === 'primary' || first.index_name.endsWith('pkey'),
unique: !first.non_unique,
columns: _.sortBy(columns, ['seq_in_index']).map((c: any) => ({
name: c.column_name,
Expand Down
4 changes: 2 additions & 2 deletions apps/studio/tests/docker/cockroachdb.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
cockroachdb:
image: cockroachdb/cockroach
image: cockroachdb/cockroach:v22.1.1
ports:
- 26257
command: start-single-node --insecure
command: start-single-node --insecure
20 changes: 2 additions & 18 deletions apps/studio/tests/lib/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DBConnection, IDbConnectionServerConfig } from '../../src/lib/db/client
import { createServer } from '../../src/lib/db/index'
import log from 'electron-log'
import platformInfo from '../../src/common/platform_info'
import { IDbConnectionPublicServer } from '@/lib/db/server'
import { IDbConnectionPublicServer } from '../../src/lib/db/server'
import { AlterTableSpec, Dialect, DialectData } from '../../../../shared/src/lib/dialects/models'
import { getDialectData } from '../../../../shared/src/lib/dialects/'
import _ from 'lodash'
Expand Down Expand Up @@ -97,7 +97,6 @@ export class DBTestUtil {
await this.connection.connect()
await this.createTables()
const address = this.maybeArrayToObject(await this.knex("addresses").insert({country: "US"}).returning("id"), 'id')
console.log("address result:", address)
await this.knex("MixedCase").insert({bananas: "pears"}).returning("id")
const people = this.maybeArrayToObject(await this.knex("people").insert({ email: "[email protected]", address_id: address[0].id}).returning("id"), 'id')
const jobs = this.maybeArrayToObject(await this.knex("jobs").insert({job_name: "Programmer"}).returning("id"), 'id')
Expand Down Expand Up @@ -128,7 +127,6 @@ export class DBTestUtil {
*/
async tableViewTests() {

console.log("table tests")
// reserved word as table name
expect(await this.connection.getPrimaryKey("group", this.defaultSchema))
.toBe("id");
Expand Down Expand Up @@ -188,7 +186,6 @@ export class DBTestUtil {
await this.connection.alterTable(simpleChange)
const simpleResult = await this.connection.listTableColumns('alter_test')

console.log(simpleResult)
expect(simpleResult.find((c) => c.columnName === 'family_name')).toBeTruthy()


Expand Down Expand Up @@ -330,7 +327,6 @@ export class DBTestUtil {

async queryTests() {
if (this.dbType === 'sqlite') return
console.log('query tests')
const q = await this.connection.query("select 'a' as total, 'b' as total")
if(!q) throw new Error("no query result")
const result = await q.execute()
Expand Down Expand Up @@ -405,7 +401,7 @@ export class DBTestUtil {
const updatedIndexes = updatedIndexesRaw.filter((i) => !i.primary)

const picked = updatedIndexes.map((i) => _.pick(i, ['name', 'columns', 'table', 'schema']))
expect(picked).toEqual(
expect(picked).toMatchObject(
[
{
name: 'it_idx2',
Expand All @@ -418,7 +414,6 @@ export class DBTestUtil {
}

async streamTests() {
console.log('selectTopStream tests')
const names = [
{ name: "Matthew" },
{ name: "Nicoll" },
Expand All @@ -440,30 +435,19 @@ export class DBTestUtil {
5,
undefined,
)
console.log("checking columns and total row count")
expect(result.columns.map(c => c.columnName)).toMatchObject(['id', 'name'])
expect(result.totalRows).toBe(6)
const cursor = result.cursor
console.log("starting cursor")
await cursor.start()
console.log("length?")
const b1 = await cursor.read()
expect(b1.length).toBe(5)
console.log("reading first five names and checking those")
console.log(b1)
expect(b1.map(r => r[1])).toMatchObject(names.map(r => r.name).slice(0, 5))
console.log("read2")
const b2 = await cursor.read()
expect(b2.length).toBe(1)
expect(b2[0][1]).toBe(names[names.length - 1].name)
console.log("read 3")
const b3 = await cursor.read()
expect(b3).toMatchObject([])
console.log("closing")
await cursor.close()



}

private async createTables() {
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ services:
- 1434:1433
command: sh -c ' chmod +x /docker_init/entrypoint.sh; /docker_init/entrypoint.sh & /opt/mssql/bin/sqlservr;'
cockroachdb:
image: cockroachdb/cockroach
image: cockroachdb/cockroach:v22.1.1
volumes:
- cockroachdb:/cockroach/cockroach-data
ports:
Expand Down

0 comments on commit 6654ca6

Please sign in to comment.