Skip to content

Commit

Permalink
fix (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit-kadhe authored Mar 28, 2024
1 parent 993ad4c commit c5ba7ad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/clickhouse_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class ClickhouseSchema<SchemaDefinition extends ChSchemaDefinition> imple
}

GetCreateTableQuery (): string {
if (this.options.primary_key === undefined && this.options.order_by === undefined) {
if (this.options.primary_key === undefined && this.options.order_by === undefined && this.options.on_cluster === undefined) {
throw new Error('One of order_by or primary_key must be specified')
}

Expand Down
16 changes: 16 additions & 0 deletions tests/unit/clickhouse_schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,20 @@ describe('ClickhouseSchema Tests', () => {
const query = schema.toString()
expect(query).toEqual(expectedQuery)
})

it('should not throw if on_cluster is specified but primary_key or order_by is not', () => {
const schemaDefinition = {
id: { type: ClickhouseTypes.CHUUID },
name: { type: ClickhouseTypes.CHString, default: 'John Doe' },
email: { type: ClickhouseTypes.CHString }
}
const options: ChSchemaOptions<typeof schemaDefinition> = {
table_name: 'users_table',
on_cluster: 'users_cluster'
}
const schema = new ClickhouseSchema(schemaDefinition, options)
const expectedQuery = 'CREATE TABLE IF NOT EXISTS users_table ON CLUSTER users_cluster\n(\nid UUID,\nname String DEFAULT \'John Doe\',\nemail String\n)\nENGINE = MergeTree()'
const query = schema.GetCreateTableQuery()
expect(query).toEqual(expectedQuery)
})
})

1 comment on commit c5ba7ad

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 100% 186/186
🟢 Branches 100% 26/26
🟢 Functions 100% 77/77
🟢 Lines 100% 164/164

Test suite run success

25 tests passing in 2 suites.

Report generated by 🧪jest coverage report action from c5ba7ad

Please sign in to comment.