mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
db/relays: add "domain" column
This commit is contained in:
parent
2e983154bb
commit
92f5bea891
3 changed files with 8 additions and 1 deletions
|
|
@ -4,6 +4,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
.createTable('relays')
|
.createTable('relays')
|
||||||
.addColumn('url', 'text', (col) => col.primaryKey())
|
.addColumn('url', 'text', (col) => col.primaryKey())
|
||||||
|
.addColumn('domain', 'text', (col) => col.notNull())
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,14 @@
|
||||||
|
import { tldts } from '@/deps.ts';
|
||||||
import { db } from '@/db.ts';
|
import { db } from '@/db.ts';
|
||||||
|
|
||||||
/** Inserts relays into the database, skipping duplicates. */
|
/** Inserts relays into the database, skipping duplicates. */
|
||||||
function addRelays(relays: `wss://${string}`[]) {
|
function addRelays(relays: `wss://${string}`[]) {
|
||||||
if (!relays.length) return Promise.resolve();
|
if (!relays.length) return Promise.resolve();
|
||||||
const values = relays.map((url) => ({ url }));
|
|
||||||
|
const values = relays.map((url) => ({
|
||||||
|
url,
|
||||||
|
domain: tldts.getDomain(url),
|
||||||
|
}));
|
||||||
|
|
||||||
return db.insertInto('relays')
|
return db.insertInto('relays')
|
||||||
.values(values)
|
.values(values)
|
||||||
|
|
|
||||||
|
|
@ -60,3 +60,4 @@ export {
|
||||||
sql,
|
sql,
|
||||||
} from 'npm:kysely@^0.25.0';
|
} from 'npm:kysely@^0.25.0';
|
||||||
export { DenoSqliteDialect } from 'https://gitlab.com/soapbox-pub/kysely-deno-sqlite/-/raw/v1.0.0/mod.ts';
|
export { DenoSqliteDialect } from 'https://gitlab.com/soapbox-pub/kysely-deno-sqlite/-/raw/v1.0.0/mod.ts';
|
||||||
|
export { default as tldts } from 'npm:tldts@^6.0.14';
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue