-
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.
feat: store and send metadata during invoice creation
- Loading branch information
1 parent
ccf1a10
commit d1da89e
Showing
9 changed files
with
4,559 additions
and
4,461 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
CREATE TABLE IF NOT EXISTS "invoices" ( | ||
"id" serial PRIMARY KEY NOT NULL, | ||
"user_id" integer NOT NULL, | ||
"amount" integer NOT NULL, | ||
"description" text, | ||
"description_hash" 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 "payment_hash_idx" ON "invoices" USING btree ("payment_hash");--> statement-breakpoint | ||
CREATE INDEX IF NOT EXISTS "user_payment_hash_idx" ON "invoices" USING btree ("user_id","payment_hash");--> statement-breakpoint | ||
CREATE INDEX IF NOT EXISTS "username_idx" ON "users" USING btree ("username"); |
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,233 @@ | ||
{ | ||
"id": "a90a8c91-5f2c-48da-9109-ae0a37820ceb", | ||
"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": "integer", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"description": { | ||
"name": "description", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"description_hash": { | ||
"name": "description_hash", | ||
"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": {} | ||
}, | ||
"payment_hash_idx": { | ||
"name": "payment_hash_idx", | ||
"columns": [ | ||
{ | ||
"expression": "payment_hash", | ||
"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": { | ||
"username_idx": { | ||
"name": "username_idx", | ||
"columns": [ | ||
{ | ||
"expression": "username", | ||
"isExpression": false, | ||
"asc": true, | ||
"nulls": "last" | ||
} | ||
], | ||
"isUnique": false, | ||
"concurrently": false, | ||
"method": "btree", | ||
"with": {} | ||
} | ||
}, | ||
"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,32 @@ | ||
import { pgTable, serial, text, timestamp } from "drizzle-orm/pg-core"; | ||
import { 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(), | ||
}, (table) => { | ||
return { | ||
usernameIdx: index("username_idx").on(table.username), | ||
}; | ||
}); | ||
|
||
export const invoices = pgTable("invoices", { | ||
id: serial("id").primaryKey(), | ||
userId: integer("user_id").references(() => users.id, { onDelete: "cascade" }).notNull(), | ||
amount: integer("amount").notNull(), | ||
description: text("description"), | ||
descriptionHash: text("description_hash"), | ||
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), | ||
paymentHashIdx: index("payment_hash_idx").on(table.paymentHash), | ||
userPaymentHashIdx: index("user_payment_hash_idx").on(table.userId, table.paymentHash), | ||
}; | ||
}); |
Oops, something went wrong.