mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-07 07:34:25 +01:00
Mold the things to work with Postgres
This commit is contained in:
@@ -56,7 +56,7 @@ interface UnattachedMediaRow {
|
||||
pubkey: string;
|
||||
url: string;
|
||||
data: string;
|
||||
uploaded_at: Date;
|
||||
uploaded_at: number;
|
||||
}
|
||||
|
||||
interface PubkeyDomainRow {
|
||||
|
||||
@@ -21,6 +21,9 @@ export class DittoSQLite {
|
||||
await Promise.all([
|
||||
sql`PRAGMA synchronous = normal`.execute(this.db),
|
||||
sql`PRAGMA temp_store = memory`.execute(this.db),
|
||||
sql`PRAGMA foreign_keys = ON`.execute(this.db),
|
||||
sql`PRAGMA auto_vacuum = FULL`.execute(this.db),
|
||||
sql`PRAGMA journal_mode = WAL`.execute(this.db),
|
||||
sql.raw(`PRAGMA mmap_size = ${Conf.sqlite.mmapSize}`).execute(this.db),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Kysely, sql } from '@/deps.ts';
|
||||
import { Kysely } from '@/deps.ts';
|
||||
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
await db.schema
|
||||
@@ -21,13 +21,6 @@ export async function up(db: Kysely<any>): Promise<void> {
|
||||
.addColumn('event_id', 'text', (col) => col.notNull())
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createTable('users')
|
||||
.addColumn('pubkey', 'text', (col) => col.primaryKey())
|
||||
.addColumn('username', 'text', (col) => col.notNull().unique())
|
||||
.addColumn('inserted_at', 'datetime', (col) => col.notNull().defaultTo(sql`CURRENT_TIMESTAMP`))
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_events_kind')
|
||||
.on('events')
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { Conf } from '@/config.ts';
|
||||
import { Kysely, sql } from '@/deps.ts';
|
||||
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
await sql`CREATE VIRTUAL TABLE events_fts USING fts5(id, content)`.execute(db);
|
||||
if (Conf.databaseUrl.protocol === 'sqlite:') {
|
||||
await sql`CREATE VIRTUAL TABLE events_fts USING fts5(id, content)`.execute(db);
|
||||
}
|
||||
}
|
||||
|
||||
export async function down(db: Kysely<any>): Promise<void> {
|
||||
await db.schema.dropTable('events_fts').execute();
|
||||
await db.schema.dropTable('events_fts').ifExists().execute();
|
||||
}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import { Kysely } from '@/deps.ts';
|
||||
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
await db.schema
|
||||
.alterTable('users')
|
||||
.addColumn('admin', 'boolean', (col) => col.defaultTo(false))
|
||||
.execute();
|
||||
export async function up(_db: Kysely<any>): Promise<void> {
|
||||
}
|
||||
|
||||
export async function down(db: Kysely<any>): Promise<void> {
|
||||
|
||||
@@ -1,17 +1,6 @@
|
||||
import { Kysely } from '@/deps.ts';
|
||||
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
await db.schema
|
||||
.createIndex('idx_users_pubkey')
|
||||
.on('users')
|
||||
.column('pubkey')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_users_username')
|
||||
.on('users')
|
||||
.column('username')
|
||||
.execute();
|
||||
export async function up(_db: Kysely<any>): Promise<void> {
|
||||
}
|
||||
|
||||
export async function down(db: Kysely<any>): Promise<void> {
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { Kysely, sql } from '@/deps.ts';
|
||||
import { Kysely } from '@/deps.ts';
|
||||
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
await sql`PRAGMA foreign_keys = ON`.execute(db);
|
||||
await sql`PRAGMA auto_vacuum = FULL`.execute(db);
|
||||
await sql`VACUUM`.execute(db);
|
||||
export async function up(_db: Kysely<any>): Promise<void> {
|
||||
}
|
||||
|
||||
export async function down(db: Kysely<any>): Promise<void> {
|
||||
await sql`PRAGMA foreign_keys = OFF`.execute(db);
|
||||
await sql`PRAGMA auto_vacuum = NONE`.execute(db);
|
||||
export async function down(_db: Kysely<any>): Promise<void> {
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Kysely, sql } from '@/deps.ts';
|
||||
import { Kysely } from '@/deps.ts';
|
||||
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
await db.schema
|
||||
@@ -7,7 +7,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
||||
.addColumn('pubkey', 'text', (c) => c.notNull())
|
||||
.addColumn('url', 'text', (c) => c.notNull())
|
||||
.addColumn('data', 'text', (c) => c.notNull())
|
||||
.addColumn('uploaded_at', 'datetime', (c) => c.notNull().defaultTo(sql`CURRENT_TIMESTAMP`))
|
||||
.addColumn('uploaded_at', 'bigint', (c) => c.notNull())
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { Kysely, sql } from '@/deps.ts';
|
||||
import { Kysely } from '@/deps.ts';
|
||||
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
await sql`PRAGMA journal_mode = WAL`.execute(db);
|
||||
export async function up(_db: Kysely<any>): Promise<void> {
|
||||
}
|
||||
|
||||
export async function down(db: Kysely<any>): Promise<void> {
|
||||
await sql`PRAGMA journal_mode = DELETE`.execute(db);
|
||||
export async function down(_db: Kysely<any>): Promise<void> {
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Kysely } from '@/deps.ts';
|
||||
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
await db.schema.dropTable('users').execute();
|
||||
await db.schema.dropTable('users').ifExists().execute();
|
||||
}
|
||||
|
||||
export async function down(_db: Kysely<any>): Promise<void> {
|
||||
|
||||
@@ -7,14 +7,14 @@ interface UnattachedMedia {
|
||||
pubkey: string;
|
||||
url: string;
|
||||
data: MediaData;
|
||||
uploaded_at: Date;
|
||||
uploaded_at: number;
|
||||
}
|
||||
|
||||
/** Add unattached media into the database. */
|
||||
async function insertUnattachedMedia(media: Omit<UnattachedMedia, 'id' | 'uploaded_at'>) {
|
||||
const result = {
|
||||
id: uuid62.v4(),
|
||||
uploaded_at: new Date(),
|
||||
uploaded_at: Date.now(),
|
||||
...media,
|
||||
};
|
||||
|
||||
@@ -41,7 +41,7 @@ function selectUnattachedMediaQuery() {
|
||||
function getUnattachedMedia(until: Date) {
|
||||
return selectUnattachedMediaQuery()
|
||||
.leftJoin('tags', 'unattached_media.url', 'tags.value')
|
||||
.where('uploaded_at', '<', until)
|
||||
.where('uploaded_at', '<', until.getTime())
|
||||
.execute();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user