-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from getAlby/task-metadata
feat: store and send metadata during invoice creation
- Loading branch information
Showing
11 changed files
with
4,515 additions
and
4,465 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"imports": { | ||
"@nostr/tools": "jsr:@nostr/tools@^2.10.3", | ||
"hono": "jsr:@hono/hono@^4.5.5", | ||
"drizzle-orm": "npm:[email protected]", | ||
"drizzle-kit": "npm:[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
CREATE TABLE IF NOT EXISTS "invoices" ( | ||
"id" serial PRIMARY KEY NOT NULL, | ||
"user_id" integer NOT NULL, | ||
"amount" bigint NOT NULL, | ||
"description" text, | ||
"payment_request" text NOT NULL, | ||
"payment_hash" text NOT NULL, | ||
"preimage" text, | ||
"metadata" jsonb, | ||
"settled_at" timestamp, | ||
"created_at" timestamp DEFAULT now() NOT NULL, | ||
CONSTRAINT "invoices_payment_request_unique" UNIQUE("payment_request"), | ||
CONSTRAINT "invoices_payment_hash_unique" UNIQUE("payment_hash") | ||
); | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "invoices" ADD CONSTRAINT "invoices_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
CREATE INDEX IF NOT EXISTS "user_id_idx" ON "invoices" USING btree ("user_id");--> statement-breakpoint | ||
CREATE INDEX IF NOT EXISTS "user_payment_hash_idx" ON "invoices" USING btree ("user_id","payment_hash"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
{ | ||
"id": "52607bd8-7a1a-4a34-ad27-91b78733e85c", | ||
"prevId": "e292703e-d08b-4f8b-a9eb-3937fe872be7", | ||
"version": "7", | ||
"dialect": "postgresql", | ||
"tables": { | ||
"public.invoices": { | ||
"name": "invoices", | ||
"schema": "", | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "serial", | ||
"primaryKey": true, | ||
"notNull": true | ||
}, | ||
"user_id": { | ||
"name": "user_id", | ||
"type": "integer", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"amount": { | ||
"name": "amount", | ||
"type": "bigint", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"description": { | ||
"name": "description", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"payment_request": { | ||
"name": "payment_request", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"payment_hash": { | ||
"name": "payment_hash", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"preimage": { | ||
"name": "preimage", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"metadata": { | ||
"name": "metadata", | ||
"type": "jsonb", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"settled_at": { | ||
"name": "settled_at", | ||
"type": "timestamp", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"created_at": { | ||
"name": "created_at", | ||
"type": "timestamp", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"default": "now()" | ||
} | ||
}, | ||
"indexes": { | ||
"user_id_idx": { | ||
"name": "user_id_idx", | ||
"columns": [ | ||
{ | ||
"expression": "user_id", | ||
"isExpression": false, | ||
"asc": true, | ||
"nulls": "last" | ||
} | ||
], | ||
"isUnique": false, | ||
"concurrently": false, | ||
"method": "btree", | ||
"with": {} | ||
}, | ||
"user_payment_hash_idx": { | ||
"name": "user_payment_hash_idx", | ||
"columns": [ | ||
{ | ||
"expression": "user_id", | ||
"isExpression": false, | ||
"asc": true, | ||
"nulls": "last" | ||
}, | ||
{ | ||
"expression": "payment_hash", | ||
"isExpression": false, | ||
"asc": true, | ||
"nulls": "last" | ||
} | ||
], | ||
"isUnique": false, | ||
"concurrently": false, | ||
"method": "btree", | ||
"with": {} | ||
} | ||
}, | ||
"foreignKeys": { | ||
"invoices_user_id_users_id_fk": { | ||
"name": "invoices_user_id_users_id_fk", | ||
"tableFrom": "invoices", | ||
"tableTo": "users", | ||
"columnsFrom": [ | ||
"user_id" | ||
], | ||
"columnsTo": [ | ||
"id" | ||
], | ||
"onDelete": "cascade", | ||
"onUpdate": "no action" | ||
} | ||
}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": { | ||
"invoices_payment_request_unique": { | ||
"name": "invoices_payment_request_unique", | ||
"nullsNotDistinct": false, | ||
"columns": [ | ||
"payment_request" | ||
] | ||
}, | ||
"invoices_payment_hash_unique": { | ||
"name": "invoices_payment_hash_unique", | ||
"nullsNotDistinct": false, | ||
"columns": [ | ||
"payment_hash" | ||
] | ||
} | ||
} | ||
}, | ||
"public.users": { | ||
"name": "users", | ||
"schema": "", | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "serial", | ||
"primaryKey": true, | ||
"notNull": true | ||
}, | ||
"connection_secret": { | ||
"name": "connection_secret", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"username": { | ||
"name": "username", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"created_at": { | ||
"name": "created_at", | ||
"type": "timestamp", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"default": "now()" | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": {}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": { | ||
"users_username_unique": { | ||
"name": "users_username_unique", | ||
"nullsNotDistinct": false, | ||
"columns": [ | ||
"username" | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"enums": {}, | ||
"schemas": {}, | ||
"sequences": {}, | ||
"_meta": { | ||
"columns": {}, | ||
"schemas": {}, | ||
"tables": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,26 @@ | ||
import { pgTable, serial, text, timestamp } from "drizzle-orm/pg-core"; | ||
import { bigint, index, integer, jsonb, pgTable, serial, text, timestamp } from "drizzle-orm/pg-core"; | ||
|
||
export const users = pgTable("users", { | ||
id: serial("id").primaryKey(), | ||
encryptedConnectionSecret: text("connection_secret").notNull(), | ||
username: text("username").unique().notNull(), | ||
createdAt: timestamp("created_at").notNull().defaultNow(), | ||
}); | ||
|
||
export const invoices = pgTable("invoices", { | ||
id: serial("id").primaryKey(), | ||
userId: integer("user_id").references(() => users.id, { onDelete: "cascade" }).notNull(), | ||
amount: bigint("amount", { mode: "number" }).notNull(), | ||
description: text("description"), | ||
paymentRequest: text("payment_request").unique().notNull(), | ||
paymentHash: text("payment_hash").unique().notNull(), | ||
preimage: text("preimage"), | ||
metadata: jsonb("metadata"), | ||
settledAt: timestamp("settled_at"), | ||
createdAt: timestamp("created_at").notNull().defaultNow(), | ||
}, (table) => { | ||
return { | ||
userIdIdx: index("user_id_idx").on(table.userId), | ||
userPaymentHashIdx: index("user_payment_hash_idx").on(table.userId, table.paymentHash), | ||
}; | ||
}); |
Oops, something went wrong.