Skip to content

Commit

Permalink
chore: do not make nostr pubkey unique
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Dec 24, 2024
1 parent 11c67a4 commit 8eebd41
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 21 deletions.
8 changes: 7 additions & 1 deletion drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { defineConfig } from "drizzle-kit";
import { DATABASE_URL } from "./src/constants.ts";
const DATABASE_URL = Deno.env.get("DATABASE_URL");

if (!DATABASE_URL) {
console.log("no DATABASE_URL provided, exiting");
Deno.exit(1);
}

export default defineConfig({
dialect: "postgresql",
schema: "./src/db/schema.ts",
Expand Down
1 change: 1 addition & 0 deletions drizzle/0002_cloudy_nitro.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "users" ADD COLUMN "nostr_pubkey" text;
2 changes: 0 additions & 2 deletions drizzle/0002_crazy_sauron.sql

This file was deleted.

9 changes: 1 addition & 8 deletions drizzle/meta/0002_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "0158a5e2-5076-4051-8e8d-2d382552344d",
"id": "b434562b-7a93-4c5f-992b-480f1ca2ed98",
"prevId": "52607bd8-7a1a-4a34-ad27-91b78733e85c",
"version": "7",
"dialect": "postgresql",
Expand Down Expand Up @@ -187,13 +187,6 @@
"columns": [
"username"
]
},
"users_nostr_pubkey_unique": {
"name": "users_nostr_pubkey_unique",
"nullsNotDistinct": false,
"columns": [
"nostr_pubkey"
]
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
{
"idx": 2,
"version": "7",
"when": 1734078845730,
"tag": "0002_crazy_sauron",
"when": 1735019256440,
"tag": "0002_cloudy_nitro",
"breakpoints": true
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const users = pgTable("users", {
id: serial("id").primaryKey(),
encryptedConnectionSecret: text("connection_secret").notNull(),
username: text("username").unique().notNull(),
nostrPubkey: text("nostr_pubkey").unique(),
nostrPubkey: text("nostr_pubkey"),
createdAt: timestamp("created_at").notNull().defaultNow(),
});

Expand Down
10 changes: 3 additions & 7 deletions src/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function createUsersApp(db: DB, nwcPool: NWCPool) {
try {
logger.debug("create user", {});

const createUserRequest: { connectionSecret: string; username?: string, nostrPubkey?: string } =
const createUserRequest: { connectionSecret: string; username?: string, nostrPubkey: string } =
await c.req.json();

if (!createUserRequest.connectionSecret) {
Expand Down Expand Up @@ -49,12 +49,8 @@ export function createUsersApp(db: DB, nwcPool: NWCPool) {
});
} catch (error) {
let reason = "" + error
if (error instanceof postgres.PostgresError) {
if (error.constraint_name === "users_username_unique") {
reason = "Username has already been taken"
} else if (error.constraint_name === "users_nostr_pubkey_unique") {
reason = "Nostr pubkey has already been taken"
}
if (error instanceof postgres.PostgresError && error.constraint_name === "users_username_unique") {
reason = "Username has already been taken"
}
return c.json({ status: "ERROR", reason });
}
Expand Down

0 comments on commit 8eebd41

Please sign in to comment.