Drop users table

This commit is contained in:
Alex Gleason 2023-12-29 17:01:23 -06:00
parent 13bf936088
commit 358396fdac
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
8 changed files with 29 additions and 19 deletions

View File

@ -1,8 +1,18 @@
import { Conf } from '@/config.ts'; import { Conf } from '@/config.ts';
import { db } from '@/db.ts'; import { db } from '@/db.ts';
import { eventsDB } from '@/db/events.ts'; import { eventsDB } from '@/db/events.ts';
import { type Kysely } from '@/deps.ts';
import { signAdminEvent } from '@/sign.ts'; import { signAdminEvent } from '@/sign.ts';
interface DB {
users: {
pubkey: string;
username: string;
inserted_at: Date;
admin: 0 | 1;
};
}
switch (Deno.args[0]) { switch (Deno.args[0]) {
case 'users-to-events': case 'users-to-events':
await usersToEvents(); await usersToEvents();
@ -14,7 +24,7 @@ switch (Deno.args[0]) {
async function usersToEvents() { async function usersToEvents() {
const { origin, host } = Conf.url; const { origin, host } = Conf.url;
for (const row of await db.selectFrom('users').selectAll().execute()) { for (const row of await (db as unknown as Kysely<DB>).selectFrom('users').selectAll().execute()) {
const event = await signAdminEvent({ const event = await signAdminEvent({
kind: 30361, kind: 30361,
tags: [ tags: [

View File

@ -42,7 +42,7 @@ const createAccountController: AppController = async (c) => {
pubkey, pubkey,
username: result.data.username, username: result.data.username,
inserted_at: new Date(), inserted_at: new Date(),
admin: 0, admin: false,
}); });
return c.json({ return c.json({

View File

@ -10,7 +10,6 @@ interface DittoDB {
events: EventRow; events: EventRow;
events_fts: EventFTSRow; events_fts: EventFTSRow;
tags: TagRow; tags: TagRow;
users: UserRow;
relays: RelayRow; relays: RelayRow;
unattached_media: UnattachedMediaRow; unattached_media: UnattachedMediaRow;
author_stats: AuthorStatsRow; author_stats: AuthorStatsRow;
@ -52,13 +51,6 @@ interface TagRow {
event_id: string; event_id: string;
} }
interface UserRow {
pubkey: string;
username: string;
inserted_at: Date;
admin: 0 | 1;
}
interface RelayRow { interface RelayRow {
url: string; url: string;
domain: string; domain: string;
@ -120,4 +112,4 @@ async function migrate() {
await migrate(); await migrate();
export { type AuthorStatsRow, db, type DittoDB, type EventRow, type EventStatsRow, type TagRow, type UserRow }; export { type AuthorStatsRow, db, type DittoDB, type EventRow, type EventStatsRow, type TagRow };

View File

@ -154,6 +154,7 @@ function getFilterQuery(filter: DittoFilter): EventQuery {
} }
} }
// FIXME: local filtering is broken.
if (typeof filter.local === 'boolean') { if (typeof filter.local === 'boolean') {
query = filter.local query = filter.local
? query.innerJoin('users', 'users.pubkey', 'events.pubkey') as typeof query ? query.innerJoin('users', 'users.pubkey', 'events.pubkey') as typeof query

View File

@ -0,0 +1,8 @@
import { Kysely } from '@/deps.ts';
export async function up(db: Kysely<any>): Promise<void> {
await db.schema.dropTable('users').execute();
}
export async function down(_db: Kysely<any>): Promise<void> {
}

View File

@ -1,10 +1,8 @@
import { Conf } from '@/config.ts'; import { Conf } from '@/config.ts';
import { Debug, type Filter, type Insertable } from '@/deps.ts'; import { Debug, type Filter } from '@/deps.ts';
import { type UserRow } from '@/db.ts';
import { eventsDB } from '@/db/events.ts'; import { eventsDB } from '@/db/events.ts';
import * as pipeline from '@/pipeline.ts'; import * as pipeline from '@/pipeline.ts';
import { signAdminEvent } from '@/sign.ts'; import { signAdminEvent } from '@/sign.ts';
import { nostrNow } from '@/utils.ts';
const debug = Debug('ditto:users'); const debug = Debug('ditto:users');
@ -16,7 +14,7 @@ interface User {
} }
/** Adds a user to the database. */ /** Adds a user to the database. */
async function insertUser(user: Insertable<UserRow>) { async function insertUser(user: User) {
debug('insertUser', JSON.stringify(user)); debug('insertUser', JSON.stringify(user));
const { origin, host } = Conf.url; const { origin, host } = Conf.url;
@ -31,7 +29,7 @@ async function insertUser(user: Insertable<UserRow>) {
['alt', `@${user.username}@${host}'s account was updated by the admins of ${host}`], ['alt', `@${user.username}@${host}'s account was updated by the admins of ${host}`],
], ],
content: '', content: '',
created_at: nostrNow(), created_at: Math.floor(user.inserted_at.getTime() / 1000),
}); });
return pipeline.handleEvent(event); return pipeline.handleEvent(event);
@ -44,7 +42,7 @@ async function insertUser(user: Insertable<UserRow>) {
* await findUser({ username: 'alex' }); * await findUser({ username: 'alex' });
* ``` * ```
*/ */
async function findUser(user: Partial<Insertable<UserRow>>): Promise<User | undefined> { async function findUser(user: Partial<User>): Promise<User | undefined> {
const filter: Filter = { kinds: [30361], authors: [Conf.pubkey], limit: 1 }; const filter: Filter = { kinds: [30361], authors: [Conf.pubkey], limit: 1 };
for (const [key, value] of Object.entries(user)) { for (const [key, value] of Object.entries(user)) {

View File

@ -1,9 +1,9 @@
import { Conf } from '@/config.ts'; import { Conf } from '@/config.ts';
import { type DittoEvent } from '@/db/events.ts';
import { findUser } from '@/db/users.ts'; import { findUser } from '@/db/users.ts';
import { lodash, nip19, type UnsignedEvent } from '@/deps.ts'; import { lodash, nip19, type UnsignedEvent } from '@/deps.ts';
import { jsonMetaContentSchema } from '@/schemas/nostr.ts'; import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
import { verifyNip05Cached } from '@/utils/nip05.ts'; import { verifyNip05Cached } from '@/utils/nip05.ts';
import { type DittoEvent } from '@/store.ts';
import { Nip05, nostrDate, nostrNow, parseNip05 } from '@/utils.ts'; import { Nip05, nostrDate, nostrNow, parseNip05 } from '@/utils.ts';
import { renderEmojis } from '@/views/mastodon/emojis.ts'; import { renderEmojis } from '@/views/mastodon/emojis.ts';

View File

@ -6,13 +6,14 @@ import { findReplyTag, nip19 } from '@/deps.ts';
import { getMediaLinks, parseNoteContent } from '@/note.ts'; import { getMediaLinks, parseNoteContent } from '@/note.ts';
import { getAuthor } from '@/queries.ts'; import { getAuthor } from '@/queries.ts';
import { jsonMediaDataSchema } from '@/schemas/nostr.ts'; import { jsonMediaDataSchema } from '@/schemas/nostr.ts';
import { DittoEvent } from '@/store.ts';
import { nostrDate } from '@/utils.ts'; import { nostrDate } from '@/utils.ts';
import { unfurlCardCached } from '@/utils/unfurl.ts'; import { unfurlCardCached } from '@/utils/unfurl.ts';
import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts'; import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
import { DittoAttachment, renderAttachment } from '@/views/mastodon/attachments.ts'; import { DittoAttachment, renderAttachment } from '@/views/mastodon/attachments.ts';
import { renderEmojis } from '@/views/mastodon/emojis.ts'; import { renderEmojis } from '@/views/mastodon/emojis.ts';
async function renderStatus(event: eventsDB.DittoEvent<1>, viewerPubkey?: string) { async function renderStatus(event: DittoEvent<1>, viewerPubkey?: string) {
const account = event.author const account = event.author
? await renderAccount({ ...event.author, author_stats: event.author_stats }) ? await renderAccount({ ...event.author, author_stats: event.author_stats })
: await accountFromPubkey(event.pubkey); : await accountFromPubkey(event.pubkey);