Do some groundwork for supporting the better-sqlite3 driver
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -140,10 +140,9 @@ describe('StaticAssetsStore', () => {
|
||||
const updated = await database('static_assets_cache')
|
||||
.where({ path: 'old' })
|
||||
.update({
|
||||
last_modified_at:
|
||||
database.client.config.client === 'sqlite3'
|
||||
? database.raw(`datetime('now', '-3600 seconds')`)
|
||||
: database.raw(`now() + interval '-3600 seconds'`),
|
||||
last_modified_at: database.client.config.client.includes('sqlite3')
|
||||
? database.raw(`datetime('now', '-3600 seconds')`)
|
||||
: database.raw(`now() + interval '-3600 seconds'`),
|
||||
});
|
||||
expect(updated).toBe(1);
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ export class StaticAssetsStore implements StaticAssetProvider {
|
||||
.where(
|
||||
'last_modified_at',
|
||||
'<=',
|
||||
this.#db.client.config.client === 'sqlite3'
|
||||
this.#db.client.config.client.includes('sqlite3')
|
||||
? this.#db.raw(`datetime('now', ?)`, [`-${maxAgeSeconds} seconds`])
|
||||
: this.#db.raw(`now() + interval '${-maxAgeSeconds} seconds'`),
|
||||
)
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
exports.up = async function up(knex) {
|
||||
// Sqlite does not support alter column.
|
||||
if (knex.client.config.client !== 'sqlite3') {
|
||||
if (knex.client.config.client.includes('sqlite3')) {
|
||||
await knex.schema.alterTable('signing_keys', table => {
|
||||
table
|
||||
.timestamp('created_at', { useTz: true, precision: 0 })
|
||||
@@ -38,7 +38,7 @@ exports.up = async function up(knex) {
|
||||
*/
|
||||
exports.down = async function down(knex) {
|
||||
// Sqlite does not support alter column.
|
||||
if (knex.client.config.client !== 'sqlite3') {
|
||||
if (knex.client.config.client.includes('sqlite3')) {
|
||||
await knex.schema.alterTable('signing_keys', table => {
|
||||
table
|
||||
.timestamp('created_at', { useTz: false, precision: 0 })
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
exports.up = async function up(knex) {
|
||||
if (knex.client.config.client === 'sqlite3') {
|
||||
if (knex.client.config.client.includes('sqlite3')) {
|
||||
await knex.schema.dropTable('metadata');
|
||||
await knex.schema.createTable('metadata', table => {
|
||||
table.increments('id').comment('Automatically generated unique ID');
|
||||
@@ -93,7 +93,7 @@ exports.up = async function up(knex) {
|
||||
};
|
||||
|
||||
exports.down = async function down(knex) {
|
||||
if (knex.client.config.client === 'sqlite3') {
|
||||
if (knex.client.config.client.includes('sqlite3')) {
|
||||
await knex.schema.dropTable('metadata');
|
||||
await knex.schema.createTable('metadata', table => {
|
||||
table
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
* @param {import('knex').Knex} knex
|
||||
*/
|
||||
exports.up = async function up(knex) {
|
||||
if (knex.client.config.client === 'sqlite3') {
|
||||
if (knex.client.config.client.includes('sqlite3')) {
|
||||
// sqlite doesn't support dropPrimary so we recreate it properly instead
|
||||
await knex.schema.dropTable('entities_relations');
|
||||
await knex.schema.createTable('entities_relations', table => {
|
||||
@@ -58,7 +58,7 @@ exports.up = async function up(knex) {
|
||||
* @param {import('knex').Knex} knex
|
||||
*/
|
||||
exports.down = async function down(knex) {
|
||||
if (knex.client.config.client === 'sqlite3') {
|
||||
if (knex.client.config.client.includes('sqlite3')) {
|
||||
await knex.schema.dropTable('entities_relations');
|
||||
await knex.schema.createTable('entities_relations', table => {
|
||||
table.comment('All relations between entities in the catalog');
|
||||
|
||||
@@ -403,10 +403,9 @@ export class DefaultProcessingDatabase implements ProcessingDatabase {
|
||||
items.map(i => i.entity_ref),
|
||||
)
|
||||
.update({
|
||||
next_update_at:
|
||||
tx.client.config.client === 'sqlite3'
|
||||
? tx.raw(`datetime('now', ?)`, [`${interval} seconds`])
|
||||
: tx.raw(`now() + interval '${interval} seconds'`),
|
||||
next_update_at: tx.client.config.client.includes('sqlite3')
|
||||
? tx.raw(`datetime('now', ?)`, [`${interval} seconds`])
|
||||
: tx.raw(`now() + interval '${interval} seconds'`),
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@@ -182,7 +182,7 @@ export class DatabaseTaskStore implements TaskStore {
|
||||
.andWhere(
|
||||
'last_heartbeat_at',
|
||||
'<=',
|
||||
this.db.client.config.client === 'sqlite3'
|
||||
this.db.client.config.client.includes('sqlite3')
|
||||
? this.db.raw(`datetime('now', ?)`, [`-${timeoutS} seconds`])
|
||||
: this.db.raw(`dateadd('second', ?, ?)`, [
|
||||
`-${timeoutS}`,
|
||||
|
||||
Reference in New Issue
Block a user