diff --git a/migrations/0030_rapid_donald_blake.sql b/migrations/0030_rapid_donald_blake.sql new file mode 100644 index 0000000..d49b77f --- /dev/null +++ b/migrations/0030_rapid_donald_blake.sql @@ -0,0 +1 @@ +CREATE INDEX `users_username_idx` ON `users` (`username`); \ No newline at end of file diff --git a/migrations/meta/0030_snapshot.json b/migrations/meta/0030_snapshot.json new file mode 100644 index 0000000..c74d0bd --- /dev/null +++ b/migrations/meta/0030_snapshot.json @@ -0,0 +1,973 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "f4f1ab5b-baa8-439b-9cfc-f3650b405f08", + "prevId": "dbf766c9-e07b-44dc-8757-19e8ea38c271", + "tables": { + "accounts": { + "name": "accounts", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "accounts_userId_idx": { + "name": "accounts_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "accounts_user_id_users_id_fk": { + "name": "accounts_user_id_users_id_fk", + "tableFrom": "accounts", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "sessions": { + "name": "sessions", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "sessions_token_unique": { + "name": "sessions_token_unique", + "columns": [ + "token" + ], + "isUnique": true + }, + "sessions_userId_idx": { + "name": "sessions_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "users": { + "name": "users", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email_verified": { + "name": "email_verified", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "display_username": { + "name": "display_username", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "bsky_app_pass": { + "name": "bsky_app_pass", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "pds": { + "name": "pds", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'https://bsky.social'" + } + }, + "indexes": { + "users_email_unique": { + "name": "users_email_unique", + "columns": [ + "email" + ], + "isUnique": true + }, + "users_username_unique": { + "name": "users_username_unique", + "columns": [ + "username" + ], + "isUnique": true + }, + "users_username_idx": { + "name": "users_username_idx", + "columns": [ + "username" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "verifications": { + "name": "verifications", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "verifications_identifier_idx": { + "name": "verifications_identifier_idx", + "columns": [ + "identifier" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "media": { + "name": "media", + "columns": { + "file": { + "name": "file", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "hasPost": { + "name": "hasPost", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "user": { + "name": "user", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "media_oldWithNoPost_idx": { + "name": "media_oldWithNoPost_idx", + "columns": [ + "hasPost", + "created_at" + ], + "isUnique": false, + "where": "hasPost = 0" + }, + "media_userid_idx": { + "name": "media_userid_idx", + "columns": [ + "user" + ], + "isUnique": false + } + }, + "foreignKeys": { + "media_user_users_id_fk": { + "name": "media_user_users_id_fk", + "tableFrom": "media", + "tableTo": "users", + "columnsFrom": [ + "user" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "posts": { + "name": "posts", + "columns": { + "uuid": { + "name": "uuid", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "scheduled_date": { + "name": "scheduled_date", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "posted": { + "name": "posted", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "postNow": { + "name": "postNow", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "embedContent": { + "name": "embedContent", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(json_array())" + }, + "repostInfo": { + "name": "repostInfo", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "uri": { + "name": "uri", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cid": { + "name": "cid", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "isRepost": { + "name": "isRepost", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "rootPost": { + "name": "rootPost", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "parentPost": { + "name": "parentPost", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "threadOrder": { + "name": "threadOrder", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": -1 + }, + "contentLabel": { + "name": "contentLabel", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'None'" + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user": { + "name": "user", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "user_idx": { + "name": "user_idx", + "columns": [ + "user" + ], + "isUnique": false + }, + "postedUpdate_idx": { + "name": "postedUpdate_idx", + "columns": [ + "updated_at", + "posted" + ], + "isUnique": false, + "where": "posted = 1" + }, + "repostOnlyUser_idx": { + "name": "repostOnlyUser_idx", + "columns": [ + "user", + "isRepost" + ], + "isUnique": false, + "where": "isRepost = 1" + }, + "postedUUID_idx": { + "name": "postedUUID_idx", + "columns": [ + "uuid", + "posted" + ], + "isUnique": false + }, + "rootPostedUUID_idx": { + "name": "rootPostedUUID_idx", + "columns": [ + "rootPost", + "posted" + ], + "isUnique": false, + "where": "rootPost is not NULL and posted = 1" + }, + "generalThread_idx": { + "name": "generalThread_idx", + "columns": [ + "parentPost", + "rootPost" + ], + "isUnique": false, + "where": "parentPost is not NULL" + }, + "threadOrder_idx": { + "name": "threadOrder_idx", + "columns": [ + "rootPost", + "threadOrder" + ], + "isUnique": false, + "where": "threadOrder <> -1" + }, + "postNowScheduledDatePosted_idx": { + "name": "postNowScheduledDatePosted_idx", + "columns": [ + "posted", + "scheduled_date", + "postNow" + ], + "isUnique": false, + "where": "posted = 0 and postNow <> 1" + }, + "repostAddOn_idx": { + "name": "repostAddOn_idx", + "columns": [ + "user", + "cid" + ], + "isUnique": false + } + }, + "foreignKeys": { + "posts_user_users_id_fk": { + "name": "posts_user_users_id_fk", + "tableFrom": "posts", + "tableTo": "users", + "columnsFrom": [ + "user" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "repostCounts": { + "name": "repostCounts", + "columns": { + "post_uuid": { + "name": "post_uuid", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "count": { + "name": "count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "repostCounts_post_uuid_posts_uuid_fk": { + "name": "repostCounts_post_uuid_posts_uuid_fk", + "tableFrom": "repostCounts", + "tableTo": "posts", + "columnsFrom": [ + "post_uuid" + ], + "columnsTo": [ + "uuid" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "reposts": { + "name": "reposts", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "post_uuid": { + "name": "post_uuid", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "scheduled_date": { + "name": "scheduled_date", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "schedule_guid": { + "name": "schedule_guid", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "repost_scheduledDate_idx": { + "name": "repost_scheduledDate_idx", + "columns": [ + "scheduled_date" + ], + "isUnique": false + }, + "repost_postid_idx": { + "name": "repost_postid_idx", + "columns": [ + "post_uuid" + ], + "isUnique": false + }, + "repost_scheduleGuid_idx": { + "name": "repost_scheduleGuid_idx", + "columns": [ + "schedule_guid", + "post_uuid" + ], + "isUnique": false + }, + "repost_noduplicates_idx": { + "name": "repost_noduplicates_idx", + "columns": [ + "post_uuid", + "scheduled_date" + ], + "isUnique": true + } + }, + "foreignKeys": { + "reposts_post_uuid_posts_uuid_fk": { + "name": "reposts_post_uuid_posts_uuid_fk", + "tableFrom": "reposts", + "tableTo": "posts", + "columnsFrom": [ + "post_uuid" + ], + "columnsTo": [ + "uuid" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "bans": { + "name": "bans", + "columns": { + "account_did": { + "name": "account_did", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "banReason": { + "name": "banReason", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "''" + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "violations": { + "name": "violations", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "user": { + "name": "user", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tosViolation": { + "name": "tosViolation", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "userPassInvalid": { + "name": "userPassInvalid", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "accountSuspended": { + "name": "accountSuspended", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "accountGone": { + "name": "accountGone", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "takenDown": { + "name": "takenDown", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "mediaTooBig": { + "name": "mediaTooBig", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "violations_user_unique": { + "name": "violations_user_unique", + "columns": [ + "user" + ], + "isUnique": true + }, + "violations_user_idx": { + "name": "violations_user_idx", + "columns": [ + "user" + ], + "isUnique": false + } + }, + "foreignKeys": { + "violations_user_users_id_fk": { + "name": "violations_user_users_id_fk", + "tableFrom": "violations", + "tableTo": "users", + "columnsFrom": [ + "user" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/migrations/meta/_journal.json b/migrations/meta/_journal.json index fcf5ecc..a408762 100644 --- a/migrations/meta/_journal.json +++ b/migrations/meta/_journal.json @@ -211,6 +211,13 @@ "when": 1774826564059, "tag": "0029_low_red_shift", "breakpoints": true + }, + { + "idx": 30, + "version": "6", + "when": 1784443377365, + "tag": "0030_rapid_donald_blake", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/db/auth.schema.ts b/src/db/auth.schema.ts index 640feed..ddf39a7 100644 --- a/src/db/auth.schema.ts +++ b/src/db/auth.schema.ts @@ -20,7 +20,10 @@ export const users = sqliteTable("users", { displayUsername: text("display_username"), bskyAppPass: text("bsky_app_pass").notNull(), pds: text("pds").default(DEFAULT_PDS).notNull(), -}); +}, (table) => [ + // doing operations based on username + index("users_username_idx").on(table.username), +]); export const sessions = sqliteTable( "sessions",