From 3ca0df427fad9a23e5493dc4cf7fc32c83408616 Mon Sep 17 00:00:00 2001 From: prodrigues Date: Fri, 30 Aug 2024 12:07:43 +0100 Subject: [PATCH] changed timestamps precision to 6 and other minor IT tests fixes --- .../tests/singlestore/singlestore-common.ts | 20 ++++++++++--------- .../singlestore/singlestore-custom.test.ts | 6 +++--- .../singlestore/singlestore-prefixed.test.ts | 9 ++++++--- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/integration-tests/tests/singlestore/singlestore-common.ts b/integration-tests/tests/singlestore/singlestore-common.ts index 433c76f34..5b7a3e37c 100644 --- a/integration-tests/tests/singlestore/singlestore-common.ts +++ b/integration-tests/tests/singlestore/singlestore-common.ts @@ -94,7 +94,7 @@ const usersTable = singlestoreTable('userstest', { name: text('name').notNull(), verified: boolean('verified').notNull().default(false), jsonb: json('jsonb').$type(), - createdAt: timestamp('created_at', { fsp: 2 }).notNull().defaultNow(), + createdAt: timestamp('created_at', { fsp: 6 }).notNull().defaultNow(), }); const users2Table = singlestoreTable('users2', { @@ -121,10 +121,10 @@ const datesTable = singlestoreTable('datestable', { date: date('date'), dateAsString: date('date_as_string', { mode: 'string' }), time: time('time', { fsp: 1 }), - datetime: datetime('datetime', { fsp: 2 }), - datetimeAsString: datetime('datetime_as_string', { fsp: 2, mode: 'string' }), - timestamp: timestamp('timestamp', { fsp: 3 }), - timestampAsString: timestamp('timestamp_as_string', { fsp: 3, mode: 'string' }), + datetime: datetime('datetime', { fsp: 6 }), + datetimeAsString: datetime('datetime_as_string', { fsp: 6, mode: 'string' }), + timestamp: timestamp('timestamp', { fsp: 6 }), + timestampAsString: timestamp('timestamp_as_string', { fsp: 6, mode: 'string' }), year: year('year'), }); @@ -175,7 +175,7 @@ const usersMySchemaTable = mySchema.table('userstest', { name: text('name').notNull(), verified: boolean('verified').notNull().default(false), jsonb: json('jsonb').$type(), - createdAt: timestamp('created_at', { fsp: 2 }).notNull().defaultNow(), + createdAt: timestamp('created_at', { fsp: 6 }).notNull().defaultNow(), }); const users2MySchemaTable = mySchema.table('users2', { @@ -985,7 +985,7 @@ export function tests(driver?: string) { expect(query).toEqual({ sql: - 'insert into `userstest` (`id`, `name`, `verified`, `jsonb`, `created_at`) values (?, ?, default, ?, default) on duplicate key update `name` = ?', + 'insert into `userstest` (`id`, `name`, `verified`, `jsonb`, `created_at`) values (?, ?, default, ?, default) on duplicate key update `id` = ?, `name` = ?', params: ['John', '["foo","bar"]', 'John1'], }); }); @@ -1764,9 +1764,10 @@ export function tests(driver?: string) { const sq = db .select({ name: sql`concat(${users2Table.name}, " modified")`.as('name') }) .from(users2Table) + .orderBy(asc(users2Table.id)) .as('sq'); - const res = await db.select({ name: sq.name }).from(sq).orderBy(asc(users2Table.id)); + const res = await db.select({ name: sq.name }).from(sq); expect(res).toEqual([{ name: 'John modified' }, { name: 'Jane modified' }]); }); @@ -1821,6 +1822,7 @@ export function tests(driver?: string) { }]); await db.insert(users2Table).values([{ id: 1, name: 'John', cityId: 1 }, { id: 2, name: 'Jane', cityId: 1 }, { + id: 3, name: 'Jack', cityId: 2, }]); @@ -2485,7 +2487,7 @@ export function tests(driver?: string) { create table \`datestable\` ( \`datetime_utc\` datetime(6), \`datetime\` datetime(6), - \`datetime_as_string\` datetime + \`datetime_as_string\` datetime(6) ) `, ); diff --git a/integration-tests/tests/singlestore/singlestore-custom.test.ts b/integration-tests/tests/singlestore/singlestore-custom.test.ts index 717a94003..5af942579 100644 --- a/integration-tests/tests/singlestore/singlestore-custom.test.ts +++ b/integration-tests/tests/singlestore/singlestore-custom.test.ts @@ -135,15 +135,15 @@ const usersTable = singlestoreTable('userstest', { name: customText('name').notNull(), verified: customBoolean('verified').notNull().default(false), jsonb: customJson('jsonb'), - createdAt: customTimestamp('created_at', { fsp: 2 }).notNull().default(sql`now()`), + createdAt: customTimestamp('created_at', { fsp: 6 }).notNull().default(sql`now()`), }); const datesTable = singlestoreTable('datestable', { date: date('date'), dateAsString: date('date_as_string', { mode: 'string' }), time: time('time', { fsp: 1 }), - datetime: datetime('datetime', { fsp: 2 }), - datetimeAsString: datetime('datetime_as_string', { fsp: 2, mode: 'string' }), + datetime: datetime('datetime', { fsp: 6 }), + datetimeAsString: datetime('datetime_as_string', { fsp: 6, mode: 'string' }), year: year('year'), }); diff --git a/integration-tests/tests/singlestore/singlestore-prefixed.test.ts b/integration-tests/tests/singlestore/singlestore-prefixed.test.ts index 95053748d..e84e10b3a 100644 --- a/integration-tests/tests/singlestore/singlestore-prefixed.test.ts +++ b/integration-tests/tests/singlestore/singlestore-prefixed.test.ts @@ -74,7 +74,7 @@ const usersTable = singlestoreTable('userstest', { name: text('name').notNull(), verified: boolean('verified').notNull().default(false), jsonb: json('jsonb').$type(), - createdAt: timestamp('created_at', { fsp: 2 }).notNull().defaultNow(), + createdAt: timestamp('created_at', { fsp: 6 }).notNull().defaultNow(), }); const users2Table = singlestoreTable('users2', { @@ -639,8 +639,8 @@ test('insert + select all possible dates', async () => { date: date('date'), dateAsString: date('date_as_string', { mode: 'string' }), time: time('time', { fsp: 1 }), - datetime: datetime('datetime', { fsp: 2 }), - datetimeAsString: datetime('datetime_as_string', { fsp: 2, mode: 'string' }), + datetime: datetime('datetime', { fsp: 6 }), + datetimeAsString: datetime('datetime_as_string', { fsp: 6, mode: 'string' }), year: year('year'), }); @@ -1272,6 +1272,9 @@ test('timestamp timezone', async () => { }); const users = await db.select().from(usersTable); + console.log(users[0]!.createdAt, users[1]!.createdAt); + console.log(Date.now()); + // check that the timestamps are set correctly for default times expect(Math.abs(users[0]!.createdAt.getTime() - Date.now())).toBeLessThan(2000);