diff --git a/.github/workflows/branch-deploys.yml b/.github/workflows/branch-deploys.yml index 4f65f47..da215d1 100644 --- a/.github/workflows/branch-deploys.yml +++ b/.github/workflows/branch-deploys.yml @@ -1,6 +1,7 @@ name: Staging Deploy on: + workflow_dispatch: push: branches: - next diff --git a/.vscode/settings.json b/.vscode/settings.json index 9e79053..ab4d198 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,8 @@ { "files.associations": { "**/*.scss": "tailwindcss" - } + }, + "github-actions.workflows.pinned.workflows": [ + ".github/workflows/branch-deploys.yml" + ] } diff --git a/db/migrations/0000_melted_imperial_guard.sql b/db/migrations/0000_breezy_surge.sql similarity index 71% rename from db/migrations/0000_melted_imperial_guard.sql rename to db/migrations/0000_breezy_surge.sql index 3617500..73f5e61 100644 --- a/db/migrations/0000_melted_imperial_guard.sql +++ b/db/migrations/0000_breezy_surge.sql @@ -8,12 +8,12 @@ CREATE TYPE "public"."account_connection_status" AS ENUM('active', 'inactive', ' CREATE TYPE "public"."theme_pref" AS ENUM('system', 'dark', 'light');--> statement-breakpoint CREATE TABLE "campaign_publications" ( "id" bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "campaign_publications_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1), - "created_at" timestamp DEFAULT now(), - "updated_at" timestamp DEFAULT now(), + "createdAt" timestamp DEFAULT now(), + "updatedAt" timestamp DEFAULT now(), "campaign" bigint NOT NULL, - "credit_allocation" uuid NOT NULL, - "publish_after" date DEFAULT now(), - "publish_before" date + "creditAllocation" uuid NOT NULL, + "publishAfter" date DEFAULT now(), + "publishBefore" date ); --> statement-breakpoint CREATE TABLE "campaigns" ( @@ -24,11 +24,11 @@ CREATE TABLE "campaigns" ( "links" text[] DEFAULT '{}', "emails" text[] DEFAULT '{}', "phones" text[] DEFAULT '{}', - "created_at" timestamp DEFAULT now(), - "updated_at" timestamp DEFAULT now(), + "createdAt" timestamp DEFAULT now(), + "updatedAt" timestamp DEFAULT now(), "categories" bigint[] DEFAULT '{}', - "created_by" bigint NOT NULL, - "redirect_url" varchar(500) + "createdBy" bigint NOT NULL, + "redirectUrl" varchar(500) ); --> statement-breakpoint CREATE TABLE "categories" ( @@ -43,20 +43,22 @@ CREATE TABLE "payment_methods" ( "provider" "payment_method_provider" NOT NULL, "params" jsonb NOT NULL, "status" "payment_method_status" DEFAULT 'active' NOT NULL, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp DEFAULT now() NOT NULL, + "createdAt" timestamp DEFAULT now() NOT NULL, + "updatedAt" timestamp DEFAULT now() NOT NULL, "owner" bigint NOT NULL ); --> statement-breakpoint CREATE TABLE "payment_transactions" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, - "payment_method" "payment_method_provider" NOT NULL, + "paymentMethod" "payment_method_provider" NOT NULL, "status" "transaction_status" NOT NULL, - "external_transaction_id" varchar(400), - "recorded_at" timestamp DEFAULT now(), - "completed_at" timestamp, - "cancelled_at" timestamp, + "externalTransactionId" varchar(400), + "recordedAt" timestamp DEFAULT now(), + "completedAt" timestamp, + "cancelledAt" timestamp, "value" real NOT NULL, + "exchangeRateSnapshot" real NOT NULL, + "convertedValue" real NOT NULL, "notes" text, "currency" varchar(10) NOT NULL, "params" jsonb, @@ -65,10 +67,9 @@ CREATE TABLE "payment_transactions" ( --> statement-breakpoint CREATE TABLE "credit_allocations" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, - "exhausted" real DEFAULT 0 NOT NULL, - "allocated" real NOT NULL, - "created_at" timestamp DEFAULT now(), - "updated_at" timestamp DEFAULT now(), + "allocated" bigint NOT NULL, + "createdAt" timestamp DEFAULT now(), + "updatedAt" timestamp DEFAULT now(), "status" "credit_allocation_status" DEFAULT 'active' NOT NULL, "wallet" uuid NOT NULL ); @@ -76,24 +77,24 @@ CREATE TABLE "credit_allocations" ( CREATE TABLE "wallet_transactions" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "value" bigint NOT NULL, - "from" uuid NOT NULL, + "from" uuid, "to" uuid NOT NULL, - "recorded_at" timestamp DEFAULT now(), - "completed_at" timestamp, - "cancelled_at" timestamp, + "recordedAt" timestamp DEFAULT now(), + "completedAt" timestamp, + "cancelledAt" timestamp, "status" "transaction_status" DEFAULT 'pending', "type" "wallet_transaction_type" NOT NULL, "notes" text, - "account_transaction" uuid, - "credit_allocation" uuid + "accountTransaction" uuid, + "creditAllocation" uuid ); --> statement-breakpoint CREATE TABLE "wallets" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, - "owned_by" bigint NOT NULL, - "created_at" timestamp DEFAULT now(), - "updated_at" timestamp DEFAULT now(), - "starting_balance" bigint DEFAULT 0 + "ownedBy" bigint NOT NULL, + "createdAt" timestamp DEFAULT now(), + "updatedAt" timestamp DEFAULT now(), + "startingBalance" bigint DEFAULT 0 ); --> statement-breakpoint CREATE TABLE "access_tokens" ( @@ -108,21 +109,21 @@ CREATE TABLE "access_tokens" ( --> statement-breakpoint CREATE TABLE "account_connections" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, - "created_at" timestamp DEFAULT now(), - "updated_at" timestamp DEFAULT now(), + "createdAt" timestamp DEFAULT now(), + "updatedAt" timestamp DEFAULT now(), "user" bigint NOT NULL, "provider" "account_connection_providers" NOT NULL, "params" jsonb NOT NULL, "status" "account_connection_status" DEFAULT 'active' NOT NULL, - "provider_id" varchar(255) NOT NULL + "providerId" varchar(255) NOT NULL ); --> statement-breakpoint CREATE TABLE "federated_credentials" ( "id" varchar(255) PRIMARY KEY NOT NULL, "provider" varchar(255) NOT NULL, - "last_access_token" varchar(500), - "created_at" timestamp DEFAULT now(), - "updated_at" timestamp DEFAULT now() + "lastAccessToken" varchar(500), + "createdAt" timestamp DEFAULT now(), + "updatedAt" timestamp DEFAULT now() ); --> statement-breakpoint CREATE TABLE "refresh_tokens" ( @@ -140,8 +141,8 @@ CREATE TABLE "refresh_tokens" ( --> statement-breakpoint CREATE TABLE "user_prefs" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, - "created_at" timestamp DEFAULT now(), - "updated_at" timestamp DEFAULT now(), + "createdAt" timestamp DEFAULT now(), + "updatedAt" timestamp DEFAULT now(), "user" bigint NOT NULL, "country" varchar(2) NOT NULL, "theme" "theme_pref" DEFAULT 'light' NOT NULL, @@ -151,10 +152,10 @@ CREATE TABLE "user_prefs" ( --> statement-breakpoint CREATE TABLE "users" ( "id" bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "users_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 100 CACHE 1), - "created_at" timestamp DEFAULT now(), - "updated_at" timestamp DEFAULT now(), + "createdAt" timestamp DEFAULT now(), + "updatedAt" timestamp DEFAULT now(), "names" varchar(100) NOT NULL, - "image_url" varchar(255), + "imageUrl" varchar(255), "email" varchar(100) NOT NULL, "dob" date, "phone" varchar(255), @@ -172,15 +173,15 @@ CREATE TABLE "verification_codes" ( ); --> statement-breakpoint ALTER TABLE "campaign_publications" ADD CONSTRAINT "campaign_publications_campaign_campaigns_id_fk" FOREIGN KEY ("campaign") REFERENCES "public"."campaigns"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint -ALTER TABLE "campaign_publications" ADD CONSTRAINT "campaign_publications_credit_allocation_credit_allocations_id_fk" FOREIGN KEY ("credit_allocation") REFERENCES "public"."credit_allocations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint -ALTER TABLE "campaigns" ADD CONSTRAINT "campaigns_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "campaign_publications" ADD CONSTRAINT "campaign_publications_creditAllocation_credit_allocations_id_fk" FOREIGN KEY ("creditAllocation") REFERENCES "public"."credit_allocations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "campaigns" ADD CONSTRAINT "campaigns_createdBy_users_id_fk" FOREIGN KEY ("createdBy") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "payment_methods" ADD CONSTRAINT "payment_methods_owner_users_id_fk" FOREIGN KEY ("owner") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "credit_allocations" ADD CONSTRAINT "credit_allocations_wallet_wallets_id_fk" FOREIGN KEY ("wallet") REFERENCES "public"."wallets"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_from_wallets_id_fk" FOREIGN KEY ("from") REFERENCES "public"."wallets"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_to_wallets_id_fk" FOREIGN KEY ("to") REFERENCES "public"."wallets"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint -ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_account_transaction_payment_transactions_id_fk" FOREIGN KEY ("account_transaction") REFERENCES "public"."payment_transactions"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint -ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_credit_allocation_credit_allocations_id_fk" FOREIGN KEY ("credit_allocation") REFERENCES "public"."credit_allocations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint -ALTER TABLE "wallets" ADD CONSTRAINT "wallets_owned_by_users_id_fk" FOREIGN KEY ("owned_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_accountTransaction_payment_transactions_id_fk" FOREIGN KEY ("accountTransaction") REFERENCES "public"."payment_transactions"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_creditAllocation_credit_allocations_id_fk" FOREIGN KEY ("creditAllocation") REFERENCES "public"."credit_allocations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "wallets" ADD CONSTRAINT "wallets_ownedBy_users_id_fk" FOREIGN KEY ("ownedBy") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "access_tokens" ADD CONSTRAINT "access_tokens_user_users_id_fk" FOREIGN KEY ("user") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "access_tokens" ADD CONSTRAINT "access_tokens_replaced_by_access_tokens_id_fk" FOREIGN KEY ("replaced_by") REFERENCES "public"."access_tokens"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "account_connections" ADD CONSTRAINT "account_connections_user_users_id_fk" FOREIGN KEY ("user") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint @@ -192,21 +193,12 @@ ALTER TABLE "user_prefs" ADD CONSTRAINT "user_prefs_user_users_id_fk" FOREIGN KE ALTER TABLE "users" ADD CONSTRAINT "users_credentials_federated_credentials_id_fk" FOREIGN KEY ("credentials") REFERENCES "public"."federated_credentials"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint CREATE UNIQUE INDEX "payment_methods_provider_owner_index" ON "payment_methods" USING btree ("provider","owner");--> statement-breakpoint CREATE UNIQUE INDEX "refresh_tokens_token_user_index" ON "refresh_tokens" USING btree ("token","user");--> statement-breakpoint -CREATE VIEW "public"."vw_funding_balances" AS (select "wallets"."id", - "wallets"."starting_balance" + - SUM( - CASE - WHEN "credit_allocations"."status" = 'active' THEN "credit_allocations"."allocated" - ELSE 0 - END - ) * -1 + - SUM( - CASE - WHEN ("wallet_transactions"."from" = "wallets"."id" and "wallet_transactions"."type" = 'funding' and "wallet_transactions"."status" = 'complete') THEN -"wallet_transactions"."value" - WHEN ("wallet_transactions"."to" = "wallets"."id" and "wallet_transactions"."type" = 'funding' and "wallet_transactions"."status" = 'complete') THEN "wallet_transactions"."value" - ELSE 0 - END - )::BIGINT as "balance", "wallets"."owned_by" from "wallets" left join "wallet_transactions" on ("wallets"."id" = "wallet_transactions"."from" or "wallets"."id" = "wallet_transactions"."to") left join "users" on "wallets"."owned_by" = "users"."id" left join "credit_allocations" on "wallets"."id" = "credit_allocations"."wallet" group by "wallets"."id", "wallets"."owned_by");--> statement-breakpoint +CREATE VIEW "public"."vw_funding_balances" AS (select "wallets"."id", "wallets"."ownedBy", + "wallets"."startingBalance" - + COALESCE("total_allocated",0) - + COALESCE("total_outgoing",0) + + COALESCE("total_incoming",0) + as "balance" from "wallets" left join (select "to", COALESCE(SUM("value"), 0) as "total_incoming" from "wallet_transactions" where "wallet_transactions"."status" = 'complete' group by "wallet_transactions"."to") "incoming_transactions" on "incoming_transactions"."to" = "wallets"."id" left join (select "from", COALESCE(SUM("value"), 0) as "total_outgoing" from "wallet_transactions" where "wallet_transactions"."status" = 'complete' group by "wallet_transactions"."from") "outgoing_transactions" on "outgoing_transactions"."from" = "wallets"."id" left join (select "wallet", COALESCE(SUM("allocated"), 0) as "total_allocated" from "credit_allocations" where "credit_allocations"."status" = 'active' group by "credit_allocations"."wallet") "allocation_summary" on "allocation_summary"."wallet" = "wallets"."id");--> statement-breakpoint CREATE VIEW "public"."vw_reward_balances" AS (select "wallets"."id", SUM( CASE @@ -214,10 +206,15 @@ CREATE VIEW "public"."vw_reward_balances" AS (select "wallets"."id", WHEN ("wallet_transactions"."to" = "wallets"."id" and "wallet_transactions"."type" = 'reward' and "wallet_transactions"."status" = 'complete') THEN "wallet_transactions"."value" ELSE 0 END - )::BIGINT as "balance", "wallets"."owned_by" from "wallets" left join "wallet_transactions" on ("wallets"."id" = "wallet_transactions"."from" or "wallets"."id" = "wallet_transactions"."to") left join "users" on "wallets"."owned_by" = "users"."id" group by "wallets"."id", "wallets"."owned_by");--> statement-breakpoint + )::BIGINT as "balance", "wallets"."ownedBy" from "wallets" left join "wallet_transactions" on ("wallets"."id" = "wallet_transactions"."from" or "wallets"."id" = "wallet_transactions"."to") left join "users" on "wallets"."ownedBy" = "users"."id" group by "wallets"."id", "wallets"."ownedBy");--> statement-breakpoint CREATE VIEW "public"."vw_credit_allocations" AS (select "credit_allocations"."id", "credit_allocations"."wallet", "credit_allocations"."allocated", - COALESCE(SUM("wallet_transactions"."value"), 0) - as "exhausted" from "credit_allocations" left join "wallet_transactions" on ("credit_allocations"."id" = "wallet_transactions"."credit_allocation" and "wallet_transactions"."type" = 'reward' and "wallet_transactions"."from" = "credit_allocations"."wallet") group by "credit_allocations"."id");--> statement-breakpoint + SUM( + CASE + WHEN ("wallet_transactions"."type" = 'reward' and "wallet_transactions"."from" = "credit_allocations"."wallet") THEN "wallet_transactions"."value" + ELSE 0 + END + ) + as "exhausted" from "credit_allocations" left join "wallet_transactions" on ("credit_allocations"."id" = "wallet_transactions"."creditAllocation" and "wallet_transactions"."type" = 'reward' and "wallet_transactions"."from" = "credit_allocations"."wallet") group by "credit_allocations"."id");--> statement-breakpoint CREATE VIEW "public"."vw_verification_codes" AS (select "hash", "created_at", ("created_at" + "window")::TIMESTAMP as "expires_at", diff --git a/db/migrations/0001_panoramic_namora.sql b/db/migrations/0001_panoramic_namora.sql deleted file mode 100644 index 44d2357..0000000 --- a/db/migrations/0001_panoramic_namora.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE "payment_transactions" ADD COLUMN "converted_value" real NOT NULL; \ No newline at end of file diff --git a/db/migrations/0002_ambitious_spirit.sql b/db/migrations/0002_ambitious_spirit.sql deleted file mode 100644 index 4d48cdd..0000000 --- a/db/migrations/0002_ambitious_spirit.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE "payment_transactions" ADD COLUMN "exchange_rate_snapshot" real NOT NULL; \ No newline at end of file diff --git a/db/migrations/0003_ancient_storm.sql b/db/migrations/0003_ancient_storm.sql deleted file mode 100644 index a7e40a0..0000000 --- a/db/migrations/0003_ancient_storm.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE "wallet_transactions" ALTER COLUMN "from" DROP NOT NULL; \ No newline at end of file diff --git a/db/migrations/meta/0000_snapshot.json b/db/migrations/meta/0000_snapshot.json index 42c4a62..0e921b4 100644 --- a/db/migrations/meta/0000_snapshot.json +++ b/db/migrations/meta/0000_snapshot.json @@ -1,5 +1,5 @@ { - "id": "dbf2407a-c5ef-4d26-8839-0035147ea608", + "id": "966723f1-b0c3-406c-b2b9-498942dd6a70", "prevId": "00000000-0000-0000-0000-000000000000", "version": "7", "dialect": "postgresql", @@ -25,15 +25,15 @@ "cycle": false } }, - "created_at": { - "name": "created_at", + "createdAt": { + "name": "createdAt", "type": "timestamp", "primaryKey": false, "notNull": false, "default": "now()" }, - "updated_at": { - "name": "updated_at", + "updatedAt": { + "name": "updatedAt", "type": "timestamp", "primaryKey": false, "notNull": false, @@ -45,21 +45,21 @@ "primaryKey": false, "notNull": true }, - "credit_allocation": { - "name": "credit_allocation", + "creditAllocation": { + "name": "creditAllocation", "type": "uuid", "primaryKey": false, "notNull": true }, - "publish_after": { - "name": "publish_after", + "publishAfter": { + "name": "publishAfter", "type": "date", "primaryKey": false, "notNull": false, "default": "now()" }, - "publish_before": { - "name": "publish_before", + "publishBefore": { + "name": "publishBefore", "type": "date", "primaryKey": false, "notNull": false @@ -80,12 +80,12 @@ "onDelete": "no action", "onUpdate": "no action" }, - "campaign_publications_credit_allocation_credit_allocations_id_fk": { - "name": "campaign_publications_credit_allocation_credit_allocations_id_fk", + "campaign_publications_creditAllocation_credit_allocations_id_fk": { + "name": "campaign_publications_creditAllocation_credit_allocations_id_fk", "tableFrom": "campaign_publications", "tableTo": "credit_allocations", "columnsFrom": [ - "credit_allocation" + "creditAllocation" ], "columnsTo": [ "id" @@ -161,15 +161,15 @@ "notNull": false, "default": "'{}'" }, - "created_at": { - "name": "created_at", + "createdAt": { + "name": "createdAt", "type": "timestamp", "primaryKey": false, "notNull": false, "default": "now()" }, - "updated_at": { - "name": "updated_at", + "updatedAt": { + "name": "updatedAt", "type": "timestamp", "primaryKey": false, "notNull": false, @@ -182,14 +182,14 @@ "notNull": false, "default": "'{}'" }, - "created_by": { - "name": "created_by", + "createdBy": { + "name": "createdBy", "type": "bigint", "primaryKey": false, "notNull": true }, - "redirect_url": { - "name": "redirect_url", + "redirectUrl": { + "name": "redirectUrl", "type": "varchar(500)", "primaryKey": false, "notNull": false @@ -197,12 +197,12 @@ }, "indexes": {}, "foreignKeys": { - "campaigns_created_by_users_id_fk": { - "name": "campaigns_created_by_users_id_fk", + "campaigns_createdBy_users_id_fk": { + "name": "campaigns_createdBy_users_id_fk", "tableFrom": "campaigns", "tableTo": "users", "columnsFrom": [ - "created_by" + "createdBy" ], "columnsTo": [ "id" @@ -297,15 +297,15 @@ "notNull": true, "default": "'active'" }, - "created_at": { - "name": "created_at", + "createdAt": { + "name": "createdAt", "type": "timestamp", "primaryKey": false, "notNull": true, "default": "now()" }, - "updated_at": { - "name": "updated_at", + "updatedAt": { + "name": "updatedAt", "type": "timestamp", "primaryKey": false, "notNull": true, @@ -373,8 +373,8 @@ "notNull": true, "default": "gen_random_uuid()" }, - "payment_method": { - "name": "payment_method", + "paymentMethod": { + "name": "paymentMethod", "type": "payment_method_provider", "typeSchema": "public", "primaryKey": false, @@ -387,27 +387,27 @@ "primaryKey": false, "notNull": true }, - "external_transaction_id": { - "name": "external_transaction_id", + "externalTransactionId": { + "name": "externalTransactionId", "type": "varchar(400)", "primaryKey": false, "notNull": false }, - "recorded_at": { - "name": "recorded_at", + "recordedAt": { + "name": "recordedAt", "type": "timestamp", "primaryKey": false, "notNull": false, "default": "now()" }, - "completed_at": { - "name": "completed_at", + "completedAt": { + "name": "completedAt", "type": "timestamp", "primaryKey": false, "notNull": false }, - "cancelled_at": { - "name": "cancelled_at", + "cancelledAt": { + "name": "cancelledAt", "type": "timestamp", "primaryKey": false, "notNull": false @@ -418,6 +418,18 @@ "primaryKey": false, "notNull": true }, + "exchangeRateSnapshot": { + "name": "exchangeRateSnapshot", + "type": "real", + "primaryKey": false, + "notNull": true + }, + "convertedValue": { + "name": "convertedValue", + "type": "real", + "primaryKey": false, + "notNull": true + }, "notes": { "name": "notes", "type": "text", @@ -462,28 +474,21 @@ "notNull": true, "default": "gen_random_uuid()" }, - "exhausted": { - "name": "exhausted", - "type": "real", - "primaryKey": false, - "notNull": true, - "default": 0 - }, "allocated": { "name": "allocated", - "type": "real", + "type": "bigint", "primaryKey": false, "notNull": true }, - "created_at": { - "name": "created_at", + "createdAt": { + "name": "createdAt", "type": "timestamp", "primaryKey": false, "notNull": false, "default": "now()" }, - "updated_at": { - "name": "updated_at", + "updatedAt": { + "name": "updatedAt", "type": "timestamp", "primaryKey": false, "notNull": false, @@ -547,7 +552,7 @@ "name": "from", "type": "uuid", "primaryKey": false, - "notNull": true + "notNull": false }, "to": { "name": "to", @@ -555,21 +560,21 @@ "primaryKey": false, "notNull": true }, - "recorded_at": { - "name": "recorded_at", + "recordedAt": { + "name": "recordedAt", "type": "timestamp", "primaryKey": false, "notNull": false, "default": "now()" }, - "completed_at": { - "name": "completed_at", + "completedAt": { + "name": "completedAt", "type": "timestamp", "primaryKey": false, "notNull": false }, - "cancelled_at": { - "name": "cancelled_at", + "cancelledAt": { + "name": "cancelledAt", "type": "timestamp", "primaryKey": false, "notNull": false @@ -595,14 +600,14 @@ "primaryKey": false, "notNull": false }, - "account_transaction": { - "name": "account_transaction", + "accountTransaction": { + "name": "accountTransaction", "type": "uuid", "primaryKey": false, "notNull": false }, - "credit_allocation": { - "name": "credit_allocation", + "creditAllocation": { + "name": "creditAllocation", "type": "uuid", "primaryKey": false, "notNull": false @@ -636,12 +641,12 @@ "onDelete": "no action", "onUpdate": "no action" }, - "wallet_transactions_account_transaction_payment_transactions_id_fk": { - "name": "wallet_transactions_account_transaction_payment_transactions_id_fk", + "wallet_transactions_accountTransaction_payment_transactions_id_fk": { + "name": "wallet_transactions_accountTransaction_payment_transactions_id_fk", "tableFrom": "wallet_transactions", "tableTo": "payment_transactions", "columnsFrom": [ - "account_transaction" + "accountTransaction" ], "columnsTo": [ "id" @@ -649,12 +654,12 @@ "onDelete": "no action", "onUpdate": "no action" }, - "wallet_transactions_credit_allocation_credit_allocations_id_fk": { - "name": "wallet_transactions_credit_allocation_credit_allocations_id_fk", + "wallet_transactions_creditAllocation_credit_allocations_id_fk": { + "name": "wallet_transactions_creditAllocation_credit_allocations_id_fk", "tableFrom": "wallet_transactions", "tableTo": "credit_allocations", "columnsFrom": [ - "credit_allocation" + "creditAllocation" ], "columnsTo": [ "id" @@ -680,28 +685,28 @@ "notNull": true, "default": "gen_random_uuid()" }, - "owned_by": { - "name": "owned_by", + "ownedBy": { + "name": "ownedBy", "type": "bigint", "primaryKey": false, "notNull": true }, - "created_at": { - "name": "created_at", + "createdAt": { + "name": "createdAt", "type": "timestamp", "primaryKey": false, "notNull": false, "default": "now()" }, - "updated_at": { - "name": "updated_at", + "updatedAt": { + "name": "updatedAt", "type": "timestamp", "primaryKey": false, "notNull": false, "default": "now()" }, - "starting_balance": { - "name": "starting_balance", + "startingBalance": { + "name": "startingBalance", "type": "bigint", "primaryKey": false, "notNull": false, @@ -710,12 +715,12 @@ }, "indexes": {}, "foreignKeys": { - "wallets_owned_by_users_id_fk": { - "name": "wallets_owned_by_users_id_fk", + "wallets_ownedBy_users_id_fk": { + "name": "wallets_ownedBy_users_id_fk", "tableFrom": "wallets", "tableTo": "users", "columnsFrom": [ - "owned_by" + "ownedBy" ], "columnsTo": [ "id" @@ -825,15 +830,15 @@ "notNull": true, "default": "gen_random_uuid()" }, - "created_at": { - "name": "created_at", + "createdAt": { + "name": "createdAt", "type": "timestamp", "primaryKey": false, "notNull": false, "default": "now()" }, - "updated_at": { - "name": "updated_at", + "updatedAt": { + "name": "updatedAt", "type": "timestamp", "primaryKey": false, "notNull": false, @@ -866,8 +871,8 @@ "notNull": true, "default": "'active'" }, - "provider_id": { - "name": "provider_id", + "providerId": { + "name": "providerId", "type": "varchar(255)", "primaryKey": false, "notNull": true @@ -911,21 +916,21 @@ "primaryKey": false, "notNull": true }, - "last_access_token": { - "name": "last_access_token", + "lastAccessToken": { + "name": "lastAccessToken", "type": "varchar(500)", "primaryKey": false, "notNull": false }, - "created_at": { - "name": "created_at", + "createdAt": { + "name": "createdAt", "type": "timestamp", "primaryKey": false, "notNull": false, "default": "now()" }, - "updated_at": { - "name": "updated_at", + "updatedAt": { + "name": "updatedAt", "type": "timestamp", "primaryKey": false, "notNull": false, @@ -1103,15 +1108,15 @@ "notNull": true, "default": "gen_random_uuid()" }, - "created_at": { - "name": "created_at", + "createdAt": { + "name": "createdAt", "type": "timestamp", "primaryKey": false, "notNull": false, "default": "now()" }, - "updated_at": { - "name": "updated_at", + "updatedAt": { + "name": "updatedAt", "type": "timestamp", "primaryKey": false, "notNull": false, @@ -1193,15 +1198,15 @@ "cycle": false } }, - "created_at": { - "name": "created_at", + "createdAt": { + "name": "createdAt", "type": "timestamp", "primaryKey": false, "notNull": false, "default": "now()" }, - "updated_at": { - "name": "updated_at", + "updatedAt": { + "name": "updatedAt", "type": "timestamp", "primaryKey": false, "notNull": false, @@ -1213,8 +1218,8 @@ "primaryKey": false, "notNull": true }, - "image_url": { - "name": "image_url", + "imageUrl": { + "name": "imageUrl", "type": "varchar(255)", "primaryKey": false, "notNull": false @@ -1418,7 +1423,7 @@ "notNull": true } }, - "definition": "select \"wallets\".\"id\", \n \"wallets\".\"starting_balance\" +\n SUM(\n CASE\n WHEN \"credit_allocations\".\"status\" = 'active' THEN \"credit_allocations\".\"allocated\"\n ELSE 0\n END\n ) * -1 +\n SUM(\n CASE\n WHEN (\"wallet_transactions\".\"from\" = \"wallets\".\"id\" and \"wallet_transactions\".\"type\" = 'funding' and \"wallet_transactions\".\"status\" = 'complete') THEN -\"wallet_transactions\".\"value\"\n WHEN (\"wallet_transactions\".\"to\" = \"wallets\".\"id\" and \"wallet_transactions\".\"type\" = 'funding' and \"wallet_transactions\".\"status\" = 'complete') THEN \"wallet_transactions\".\"value\"\n ELSE 0\n END\n )::BIGINT as \"balance\", \"wallets\".\"owned_by\" from \"wallets\" left join \"wallet_transactions\" on (\"wallets\".\"id\" = \"wallet_transactions\".\"from\" or \"wallets\".\"id\" = \"wallet_transactions\".\"to\") left join \"users\" on \"wallets\".\"owned_by\" = \"users\".\"id\" left join \"credit_allocations\" on \"wallets\".\"id\" = \"credit_allocations\".\"wallet\" group by \"wallets\".\"id\", \"wallets\".\"owned_by\"", + "definition": "select \"wallets\".\"id\", \"wallets\".\"ownedBy\", \n \"wallets\".\"startingBalance\" -\n COALESCE(\"total_allocated\",0) -\n COALESCE(\"total_outgoing\",0) +\n COALESCE(\"total_incoming\",0)\n as \"balance\" from \"wallets\" left join (select \"to\", COALESCE(SUM(\"value\"), 0) as \"total_incoming\" from \"wallet_transactions\" where \"wallet_transactions\".\"status\" = 'complete' group by \"wallet_transactions\".\"to\") \"incoming_transactions\" on \"incoming_transactions\".\"to\" = \"wallets\".\"id\" left join (select \"from\", COALESCE(SUM(\"value\"), 0) as \"total_outgoing\" from \"wallet_transactions\" where \"wallet_transactions\".\"status\" = 'complete' group by \"wallet_transactions\".\"from\") \"outgoing_transactions\" on \"outgoing_transactions\".\"from\" = \"wallets\".\"id\" left join (select \"wallet\", COALESCE(SUM(\"allocated\"), 0) as \"total_allocated\" from \"credit_allocations\" where \"credit_allocations\".\"status\" = 'active' group by \"credit_allocations\".\"wallet\") \"allocation_summary\" on \"allocation_summary\".\"wallet\" = \"wallets\".\"id\"", "name": "vw_funding_balances", "schema": "public", "isExisting": false, @@ -1440,7 +1445,7 @@ "notNull": true } }, - "definition": "select \"wallets\".\"id\", \n SUM(\n CASE\n WHEN (\"wallet_transactions\".\"from\" = \"wallets\".\"id\" and \"wallet_transactions\".\"type\" = 'reward' and \"wallet_transactions\".\"status\" = 'complete') THEN -\"wallet_transactions\".\"value\"\n WHEN (\"wallet_transactions\".\"to\" = \"wallets\".\"id\" and \"wallet_transactions\".\"type\" = 'reward' and \"wallet_transactions\".\"status\" = 'complete') THEN \"wallet_transactions\".\"value\"\n ELSE 0\n END\n )::BIGINT as \"balance\", \"wallets\".\"owned_by\" from \"wallets\" left join \"wallet_transactions\" on (\"wallets\".\"id\" = \"wallet_transactions\".\"from\" or \"wallets\".\"id\" = \"wallet_transactions\".\"to\") left join \"users\" on \"wallets\".\"owned_by\" = \"users\".\"id\" group by \"wallets\".\"id\", \"wallets\".\"owned_by\"", + "definition": "select \"wallets\".\"id\", \n SUM(\n CASE\n WHEN (\"wallet_transactions\".\"from\" = \"wallets\".\"id\" and \"wallet_transactions\".\"type\" = 'reward' and \"wallet_transactions\".\"status\" = 'complete') THEN -\"wallet_transactions\".\"value\"\n WHEN (\"wallet_transactions\".\"to\" = \"wallets\".\"id\" and \"wallet_transactions\".\"type\" = 'reward' and \"wallet_transactions\".\"status\" = 'complete') THEN \"wallet_transactions\".\"value\"\n ELSE 0\n END\n )::BIGINT as \"balance\", \"wallets\".\"ownedBy\" from \"wallets\" left join \"wallet_transactions\" on (\"wallets\".\"id\" = \"wallet_transactions\".\"from\" or \"wallets\".\"id\" = \"wallet_transactions\".\"to\") left join \"users\" on \"wallets\".\"ownedBy\" = \"users\".\"id\" group by \"wallets\".\"id\", \"wallets\".\"ownedBy\"", "name": "vw_reward_balances", "schema": "public", "isExisting": false, @@ -1463,12 +1468,12 @@ }, "allocated": { "name": "allocated", - "type": "real", + "type": "bigint", "primaryKey": false, "notNull": true } }, - "definition": "select \"credit_allocations\".\"id\", \"credit_allocations\".\"wallet\", \"credit_allocations\".\"allocated\", \n COALESCE(SUM(\"wallet_transactions\".\"value\"), 0)\n as \"exhausted\" from \"credit_allocations\" left join \"wallet_transactions\" on (\"credit_allocations\".\"id\" = \"wallet_transactions\".\"credit_allocation\" and \"wallet_transactions\".\"type\" = 'reward' and \"wallet_transactions\".\"from\" = \"credit_allocations\".\"wallet\") group by \"credit_allocations\".\"id\"", + "definition": "select \"credit_allocations\".\"id\", \"credit_allocations\".\"wallet\", \"credit_allocations\".\"allocated\", \n SUM(\n CASE\n WHEN (\"wallet_transactions\".\"type\" = 'reward' and \"wallet_transactions\".\"from\" = \"credit_allocations\".\"wallet\") THEN \"wallet_transactions\".\"value\"\n ELSE 0\n END\n )\n as \"exhausted\" from \"credit_allocations\" left join \"wallet_transactions\" on (\"credit_allocations\".\"id\" = \"wallet_transactions\".\"creditAllocation\" and \"wallet_transactions\".\"type\" = 'reward' and \"wallet_transactions\".\"from\" = \"credit_allocations\".\"wallet\") group by \"credit_allocations\".\"id\"", "name": "vw_credit_allocations", "schema": "public", "isExisting": false, diff --git a/db/migrations/meta/0001_snapshot.json b/db/migrations/meta/0001_snapshot.json deleted file mode 100644 index 1f90163..0000000 --- a/db/migrations/meta/0001_snapshot.json +++ /dev/null @@ -1,1611 +0,0 @@ -{ - "id": "a6e89df8-f046-4421-a0c7-fe9172e85adc", - "prevId": "dbf2407a-c5ef-4d26-8839-0035147ea608", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.campaign_publications": { - "name": "campaign_publications", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "bigint", - "primaryKey": true, - "notNull": true, - "identity": { - "type": "always", - "name": "campaign_publications_id_seq", - "schema": "public", - "increment": "1", - "startWith": "1", - "minValue": "1", - "maxValue": "9223372036854775807", - "cache": "1", - "cycle": false - } - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "campaign": { - "name": "campaign", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "credit_allocation": { - "name": "credit_allocation", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "publish_after": { - "name": "publish_after", - "type": "date", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "publish_before": { - "name": "publish_before", - "type": "date", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "campaign_publications_campaign_campaigns_id_fk": { - "name": "campaign_publications_campaign_campaigns_id_fk", - "tableFrom": "campaign_publications", - "tableTo": "campaigns", - "columnsFrom": [ - "campaign" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "campaign_publications_credit_allocation_credit_allocations_id_fk": { - "name": "campaign_publications_credit_allocation_credit_allocations_id_fk", - "tableFrom": "campaign_publications", - "tableTo": "credit_allocations", - "columnsFrom": [ - "credit_allocation" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.campaigns": { - "name": "campaigns", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "bigint", - "primaryKey": true, - "notNull": true, - "identity": { - "type": "always", - "name": "campaigns_id_seq", - "schema": "public", - "increment": "1", - "startWith": "1", - "minValue": "1", - "maxValue": "9223372036854775807", - "cache": "1", - "cycle": false - } - }, - "title": { - "name": "title", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "media": { - "name": "media", - "type": "text[]", - "primaryKey": false, - "notNull": false, - "default": "'{}'" - }, - "links": { - "name": "links", - "type": "text[]", - "primaryKey": false, - "notNull": false, - "default": "'{}'" - }, - "emails": { - "name": "emails", - "type": "text[]", - "primaryKey": false, - "notNull": false, - "default": "'{}'" - }, - "phones": { - "name": "phones", - "type": "text[]", - "primaryKey": false, - "notNull": false, - "default": "'{}'" - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "categories": { - "name": "categories", - "type": "bigint[]", - "primaryKey": false, - "notNull": false, - "default": "'{}'" - }, - "created_by": { - "name": "created_by", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "redirect_url": { - "name": "redirect_url", - "type": "varchar(500)", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "campaigns_created_by_users_id_fk": { - "name": "campaigns_created_by_users_id_fk", - "tableFrom": "campaigns", - "tableTo": "users", - "columnsFrom": [ - "created_by" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.categories": { - "name": "categories", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "bigint", - "primaryKey": true, - "notNull": true, - "identity": { - "type": "always", - "name": "categories_id_seq", - "schema": "public", - "increment": "1", - "startWith": "1", - "minValue": "1", - "maxValue": "9223372036854775807", - "cache": "1", - "cycle": false - } - }, - "title": { - "name": "title", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "image": { - "name": "image", - "type": "varchar(500)", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.payment_methods": { - "name": "payment_methods", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "provider": { - "name": "provider", - "type": "payment_method_provider", - "typeSchema": "public", - "primaryKey": false, - "notNull": true - }, - "params": { - "name": "params", - "type": "jsonb", - "primaryKey": false, - "notNull": true - }, - "status": { - "name": "status", - "type": "payment_method_status", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'active'" - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "owner": { - "name": "owner", - "type": "bigint", - "primaryKey": false, - "notNull": true - } - }, - "indexes": { - "payment_methods_provider_owner_index": { - "name": "payment_methods_provider_owner_index", - "columns": [ - { - "expression": "provider", - "isExpression": false, - "asc": true, - "nulls": "last" - }, - { - "expression": "owner", - "isExpression": false, - "asc": true, - "nulls": "last" - } - ], - "isUnique": true, - "concurrently": false, - "method": "btree", - "with": {} - } - }, - "foreignKeys": { - "payment_methods_owner_users_id_fk": { - "name": "payment_methods_owner_users_id_fk", - "tableFrom": "payment_methods", - "tableTo": "users", - "columnsFrom": [ - "owner" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.payment_transactions": { - "name": "payment_transactions", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "payment_method": { - "name": "payment_method", - "type": "payment_method_provider", - "typeSchema": "public", - "primaryKey": false, - "notNull": true - }, - "status": { - "name": "status", - "type": "transaction_status", - "typeSchema": "public", - "primaryKey": false, - "notNull": true - }, - "external_transaction_id": { - "name": "external_transaction_id", - "type": "varchar(400)", - "primaryKey": false, - "notNull": false - }, - "recorded_at": { - "name": "recorded_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "completed_at": { - "name": "completed_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "cancelled_at": { - "name": "cancelled_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "value": { - "name": "value", - "type": "real", - "primaryKey": false, - "notNull": true - }, - "converted_value": { - "name": "converted_value", - "type": "real", - "primaryKey": false, - "notNull": true - }, - "notes": { - "name": "notes", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "currency": { - "name": "currency", - "type": "varchar(10)", - "primaryKey": false, - "notNull": true - }, - "params": { - "name": "params", - "type": "jsonb", - "primaryKey": false, - "notNull": false - }, - "inbound": { - "name": "inbound", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.credit_allocations": { - "name": "credit_allocations", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "exhausted": { - "name": "exhausted", - "type": "real", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "allocated": { - "name": "allocated", - "type": "real", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "status": { - "name": "status", - "type": "credit_allocation_status", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'active'" - }, - "wallet": { - "name": "wallet", - "type": "uuid", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "credit_allocations_wallet_wallets_id_fk": { - "name": "credit_allocations_wallet_wallets_id_fk", - "tableFrom": "credit_allocations", - "tableTo": "wallets", - "columnsFrom": [ - "wallet" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.wallet_transactions": { - "name": "wallet_transactions", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "value": { - "name": "value", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "from": { - "name": "from", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "to": { - "name": "to", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "recorded_at": { - "name": "recorded_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "completed_at": { - "name": "completed_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "cancelled_at": { - "name": "cancelled_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "status": { - "name": "status", - "type": "transaction_status", - "typeSchema": "public", - "primaryKey": false, - "notNull": false, - "default": "'pending'" - }, - "type": { - "name": "type", - "type": "wallet_transaction_type", - "typeSchema": "public", - "primaryKey": false, - "notNull": true - }, - "notes": { - "name": "notes", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "account_transaction": { - "name": "account_transaction", - "type": "uuid", - "primaryKey": false, - "notNull": false - }, - "credit_allocation": { - "name": "credit_allocation", - "type": "uuid", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "wallet_transactions_from_wallets_id_fk": { - "name": "wallet_transactions_from_wallets_id_fk", - "tableFrom": "wallet_transactions", - "tableTo": "wallets", - "columnsFrom": [ - "from" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "wallet_transactions_to_wallets_id_fk": { - "name": "wallet_transactions_to_wallets_id_fk", - "tableFrom": "wallet_transactions", - "tableTo": "wallets", - "columnsFrom": [ - "to" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "wallet_transactions_account_transaction_payment_transactions_id_fk": { - "name": "wallet_transactions_account_transaction_payment_transactions_id_fk", - "tableFrom": "wallet_transactions", - "tableTo": "payment_transactions", - "columnsFrom": [ - "account_transaction" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "wallet_transactions_credit_allocation_credit_allocations_id_fk": { - "name": "wallet_transactions_credit_allocation_credit_allocations_id_fk", - "tableFrom": "wallet_transactions", - "tableTo": "credit_allocations", - "columnsFrom": [ - "credit_allocation" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.wallets": { - "name": "wallets", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "owned_by": { - "name": "owned_by", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "starting_balance": { - "name": "starting_balance", - "type": "bigint", - "primaryKey": false, - "notNull": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "wallets_owned_by_users_id_fk": { - "name": "wallets_owned_by_users_id_fk", - "tableFrom": "wallets", - "tableTo": "users", - "columnsFrom": [ - "owned_by" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.access_tokens": { - "name": "access_tokens", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "ip": { - "name": "ip", - "type": "varchar(39)", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "revoked_at": { - "name": "revoked_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "window": { - "name": "window", - "type": "interval", - "primaryKey": false, - "notNull": true - }, - "user": { - "name": "user", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "replaced_by": { - "name": "replaced_by", - "type": "uuid", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "access_tokens_user_users_id_fk": { - "name": "access_tokens_user_users_id_fk", - "tableFrom": "access_tokens", - "tableTo": "users", - "columnsFrom": [ - "user" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "access_tokens_replaced_by_access_tokens_id_fk": { - "name": "access_tokens_replaced_by_access_tokens_id_fk", - "tableFrom": "access_tokens", - "tableTo": "access_tokens", - "columnsFrom": [ - "replaced_by" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.account_connections": { - "name": "account_connections", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "user": { - "name": "user", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "provider": { - "name": "provider", - "type": "account_connection_providers", - "typeSchema": "public", - "primaryKey": false, - "notNull": true - }, - "params": { - "name": "params", - "type": "jsonb", - "primaryKey": false, - "notNull": true - }, - "status": { - "name": "status", - "type": "account_connection_status", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'active'" - }, - "provider_id": { - "name": "provider_id", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "account_connections_user_users_id_fk": { - "name": "account_connections_user_users_id_fk", - "tableFrom": "account_connections", - "tableTo": "users", - "columnsFrom": [ - "user" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.federated_credentials": { - "name": "federated_credentials", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "varchar(255)", - "primaryKey": true, - "notNull": true - }, - "provider": { - "name": "provider", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "last_access_token": { - "name": "last_access_token", - "type": "varchar(500)", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.refresh_tokens": { - "name": "refresh_tokens", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "token": { - "name": "token", - "type": "varchar(32)", - "primaryKey": false, - "notNull": true - }, - "user": { - "name": "user", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "ip": { - "name": "ip", - "type": "varchar(39)", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "replaced_by": { - "name": "replaced_by", - "type": "uuid", - "primaryKey": false, - "notNull": false - }, - "revoked_by": { - "name": "revoked_by", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "window": { - "name": "window", - "type": "interval", - "primaryKey": false, - "notNull": true - }, - "access_token": { - "name": "access_token", - "type": "uuid", - "primaryKey": false, - "notNull": true - } - }, - "indexes": { - "refresh_tokens_token_user_index": { - "name": "refresh_tokens_token_user_index", - "columns": [ - { - "expression": "token", - "isExpression": false, - "asc": true, - "nulls": "last" - }, - { - "expression": "user", - "isExpression": false, - "asc": true, - "nulls": "last" - } - ], - "isUnique": true, - "concurrently": false, - "method": "btree", - "with": {} - } - }, - "foreignKeys": { - "refresh_tokens_user_users_id_fk": { - "name": "refresh_tokens_user_users_id_fk", - "tableFrom": "refresh_tokens", - "tableTo": "users", - "columnsFrom": [ - "user" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "refresh_tokens_replaced_by_refresh_tokens_id_fk": { - "name": "refresh_tokens_replaced_by_refresh_tokens_id_fk", - "tableFrom": "refresh_tokens", - "tableTo": "refresh_tokens", - "columnsFrom": [ - "replaced_by" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "refresh_tokens_revoked_by_users_id_fk": { - "name": "refresh_tokens_revoked_by_users_id_fk", - "tableFrom": "refresh_tokens", - "tableTo": "users", - "columnsFrom": [ - "revoked_by" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "refresh_tokens_access_token_access_tokens_id_fk": { - "name": "refresh_tokens_access_token_access_tokens_id_fk", - "tableFrom": "refresh_tokens", - "tableTo": "access_tokens", - "columnsFrom": [ - "access_token" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "refresh_tokens_token_unique": { - "name": "refresh_tokens_token_unique", - "nullsNotDistinct": false, - "columns": [ - "token" - ] - } - }, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.user_prefs": { - "name": "user_prefs", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "user": { - "name": "user", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "country": { - "name": "country", - "type": "varchar(2)", - "primaryKey": false, - "notNull": true - }, - "theme": { - "name": "theme", - "type": "theme_pref", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'light'" - }, - "currency": { - "name": "currency", - "type": "varchar(3)", - "primaryKey": false, - "notNull": true - }, - "language": { - "name": "language", - "type": "varchar(2)", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "user_prefs_user_users_id_fk": { - "name": "user_prefs_user_users_id_fk", - "tableFrom": "user_prefs", - "tableTo": "users", - "columnsFrom": [ - "user" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.users": { - "name": "users", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "bigint", - "primaryKey": true, - "notNull": true, - "identity": { - "type": "always", - "name": "users_id_seq", - "schema": "public", - "increment": "1", - "startWith": "100", - "minValue": "1", - "maxValue": "9223372036854775807", - "cache": "1", - "cycle": false - } - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "names": { - "name": "names", - "type": "varchar(100)", - "primaryKey": false, - "notNull": true - }, - "image_url": { - "name": "image_url", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false - }, - "email": { - "name": "email", - "type": "varchar(100)", - "primaryKey": false, - "notNull": true - }, - "dob": { - "name": "dob", - "type": "date", - "primaryKey": false, - "notNull": false - }, - "phone": { - "name": "phone", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false - }, - "credentials": { - "name": "credentials", - "type": "varchar", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "users_credentials_federated_credentials_id_fk": { - "name": "users_credentials_federated_credentials_id_fk", - "tableFrom": "users", - "tableTo": "federated_credentials", - "columnsFrom": [ - "credentials" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.verification_codes": { - "name": "verification_codes", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "window": { - "name": "window", - "type": "interval", - "primaryKey": false, - "notNull": true - }, - "hash": { - "name": "hash", - "type": "varchar(32)", - "primaryKey": false, - "notNull": true - }, - "confirmed_at": { - "name": "confirmed_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "data": { - "name": "data", - "type": "jsonb", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "verification_codes_hash_unique": { - "name": "verification_codes_hash_unique", - "nullsNotDistinct": false, - "columns": [ - "hash" - ] - } - }, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - } - }, - "enums": { - "public.credit_allocation_status": { - "name": "credit_allocation_status", - "schema": "public", - "values": [ - "active", - "cancelled", - "complete" - ] - }, - "public.payment_method_provider": { - "name": "payment_method_provider", - "schema": "public", - "values": [ - "momo", - "virtual" - ] - }, - "public.payment_method_status": { - "name": "payment_method_status", - "schema": "public", - "values": [ - "active", - "inactive", - "re-connection required" - ] - }, - "public.transaction_status": { - "name": "transaction_status", - "schema": "public", - "values": [ - "pending", - "cancelled", - "complete" - ] - }, - "public.wallet_transaction_type": { - "name": "wallet_transaction_type", - "schema": "public", - "values": [ - "funding", - "reward", - "withdrawal" - ] - }, - "public.account_connection_providers": { - "name": "account_connection_providers", - "schema": "public", - "values": [ - "telegram" - ] - }, - "public.account_connection_status": { - "name": "account_connection_status", - "schema": "public", - "values": [ - "active", - "inactive", - "reconnect_required" - ] - }, - "public.theme_pref": { - "name": "theme_pref", - "schema": "public", - "values": [ - "system", - "dark", - "light" - ] - } - }, - "schemas": {}, - "sequences": {}, - "roles": {}, - "policies": {}, - "views": { - "public.vw_funding_balances": { - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "ownedBy": { - "name": "ownedBy", - "type": "bigint", - "primaryKey": false, - "notNull": true - } - }, - "definition": "select \"wallets\".\"id\", \n \"wallets\".\"starting_balance\" +\n SUM(\n CASE\n WHEN \"credit_allocations\".\"status\" = 'active' THEN \"credit_allocations\".\"allocated\"\n ELSE 0\n END\n ) * -1 +\n SUM(\n CASE\n WHEN (\"wallet_transactions\".\"from\" = \"wallets\".\"id\" and \"wallet_transactions\".\"type\" = 'funding' and \"wallet_transactions\".\"status\" = 'complete') THEN -\"wallet_transactions\".\"value\"\n WHEN (\"wallet_transactions\".\"to\" = \"wallets\".\"id\" and \"wallet_transactions\".\"type\" = 'funding' and \"wallet_transactions\".\"status\" = 'complete') THEN \"wallet_transactions\".\"value\"\n ELSE 0\n END\n )::BIGINT as \"balance\", \"wallets\".\"owned_by\" from \"wallets\" left join \"wallet_transactions\" on (\"wallets\".\"id\" = \"wallet_transactions\".\"from\" or \"wallets\".\"id\" = \"wallet_transactions\".\"to\") left join \"users\" on \"wallets\".\"owned_by\" = \"users\".\"id\" left join \"credit_allocations\" on \"wallets\".\"id\" = \"credit_allocations\".\"wallet\" group by \"wallets\".\"id\", \"wallets\".\"owned_by\"", - "name": "vw_funding_balances", - "schema": "public", - "isExisting": false, - "materialized": false - }, - "public.vw_reward_balances": { - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "ownedBy": { - "name": "ownedBy", - "type": "bigint", - "primaryKey": false, - "notNull": true - } - }, - "definition": "select \"wallets\".\"id\", \n SUM(\n CASE\n WHEN (\"wallet_transactions\".\"from\" = \"wallets\".\"id\" and \"wallet_transactions\".\"type\" = 'reward' and \"wallet_transactions\".\"status\" = 'complete') THEN -\"wallet_transactions\".\"value\"\n WHEN (\"wallet_transactions\".\"to\" = \"wallets\".\"id\" and \"wallet_transactions\".\"type\" = 'reward' and \"wallet_transactions\".\"status\" = 'complete') THEN \"wallet_transactions\".\"value\"\n ELSE 0\n END\n )::BIGINT as \"balance\", \"wallets\".\"owned_by\" from \"wallets\" left join \"wallet_transactions\" on (\"wallets\".\"id\" = \"wallet_transactions\".\"from\" or \"wallets\".\"id\" = \"wallet_transactions\".\"to\") left join \"users\" on \"wallets\".\"owned_by\" = \"users\".\"id\" group by \"wallets\".\"id\", \"wallets\".\"owned_by\"", - "name": "vw_reward_balances", - "schema": "public", - "isExisting": false, - "materialized": false - }, - "public.vw_credit_allocations": { - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "wallet": { - "name": "wallet", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "allocated": { - "name": "allocated", - "type": "real", - "primaryKey": false, - "notNull": true - } - }, - "definition": "select \"credit_allocations\".\"id\", \"credit_allocations\".\"wallet\", \"credit_allocations\".\"allocated\", \n COALESCE(SUM(\"wallet_transactions\".\"value\"), 0)\n as \"exhausted\" from \"credit_allocations\" left join \"wallet_transactions\" on (\"credit_allocations\".\"id\" = \"wallet_transactions\".\"credit_allocation\" and \"wallet_transactions\".\"type\" = 'reward' and \"wallet_transactions\".\"from\" = \"credit_allocations\".\"wallet\") group by \"credit_allocations\".\"id\"", - "name": "vw_credit_allocations", - "schema": "public", - "isExisting": false, - "materialized": false - }, - "public.vw_verification_codes": { - "columns": { - "hash": { - "name": "hash", - "type": "varchar(32)", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "data": { - "name": "data", - "type": "jsonb", - "primaryKey": false, - "notNull": false - } - }, - "definition": "select \"hash\", \"created_at\", \n (\"created_at\" + \"window\")::TIMESTAMP\n as \"expires_at\", \n (CASE\n WHEN \"confirmed_at\" IS NOT NULL THEN true\n ELSE NOW() > (\"created_at\" + \"window\")\n END)::BOOlEAN\n as \"is_expired\", \"data\" from \"verification_codes\"", - "name": "vw_verification_codes", - "schema": "public", - "isExisting": false, - "materialized": false - }, - "public.vw_access_tokens": { - "columns": { - "user": { - "name": "user", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "ip": { - "name": "ip", - "type": "varchar(39)", - "primaryKey": false, - "notNull": true - }, - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - } - }, - "definition": "select \"user\", (now() > (\"created_at\" + \"window\")::TIMESTAMP)::BOOLEAN OR revoked_at IS NOT NULL OR replaced_by IS NOT NULL as \"is_expired\", (created_at + \"window\")::TIMESTAMP as \"expires_at\", \"created_at\", \"ip\", \"id\" from \"access_tokens\"", - "name": "vw_access_tokens", - "schema": "public", - "isExisting": false, - "materialized": false - }, - "public.vw_refresh_tokens": { - "columns": { - "revoked_by": { - "name": "revoked_by", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "replaced_by": { - "name": "replaced_by", - "type": "uuid", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "access_token": { - "name": "access_token", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "ip": { - "name": "ip", - "type": "varchar(39)", - "primaryKey": false, - "notNull": true - }, - "user": { - "name": "user", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "token": { - "name": "token", - "type": "varchar(32)", - "primaryKey": false, - "notNull": true - }, - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - } - }, - "definition": "select (now()::TIMESTAMP > (\"created_at\" + \"window\")::TIMESTAMP)::BOOLEAN OR \"revoked_by\" IS NOT NULL as \"is_expired\", (\"created_at\" + \"window\")::TIMESTAMP as \"expires\", \"revoked_by\", \"replaced_by\", \"created_at\", \"access_token\", \"ip\", \"user\", \"token\", \"id\" from \"refresh_tokens\"", - "name": "vw_refresh_tokens", - "schema": "public", - "isExisting": false, - "materialized": false - } - }, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/db/migrations/meta/0002_snapshot.json b/db/migrations/meta/0002_snapshot.json deleted file mode 100644 index 94cb98f..0000000 --- a/db/migrations/meta/0002_snapshot.json +++ /dev/null @@ -1,1617 +0,0 @@ -{ - "id": "fb1a4aac-1e52-434f-9a05-f9f8158d857d", - "prevId": "a6e89df8-f046-4421-a0c7-fe9172e85adc", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.campaign_publications": { - "name": "campaign_publications", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "bigint", - "primaryKey": true, - "notNull": true, - "identity": { - "type": "always", - "name": "campaign_publications_id_seq", - "schema": "public", - "increment": "1", - "startWith": "1", - "minValue": "1", - "maxValue": "9223372036854775807", - "cache": "1", - "cycle": false - } - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "campaign": { - "name": "campaign", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "credit_allocation": { - "name": "credit_allocation", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "publish_after": { - "name": "publish_after", - "type": "date", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "publish_before": { - "name": "publish_before", - "type": "date", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "campaign_publications_campaign_campaigns_id_fk": { - "name": "campaign_publications_campaign_campaigns_id_fk", - "tableFrom": "campaign_publications", - "tableTo": "campaigns", - "columnsFrom": [ - "campaign" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "campaign_publications_credit_allocation_credit_allocations_id_fk": { - "name": "campaign_publications_credit_allocation_credit_allocations_id_fk", - "tableFrom": "campaign_publications", - "tableTo": "credit_allocations", - "columnsFrom": [ - "credit_allocation" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.campaigns": { - "name": "campaigns", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "bigint", - "primaryKey": true, - "notNull": true, - "identity": { - "type": "always", - "name": "campaigns_id_seq", - "schema": "public", - "increment": "1", - "startWith": "1", - "minValue": "1", - "maxValue": "9223372036854775807", - "cache": "1", - "cycle": false - } - }, - "title": { - "name": "title", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "media": { - "name": "media", - "type": "text[]", - "primaryKey": false, - "notNull": false, - "default": "'{}'" - }, - "links": { - "name": "links", - "type": "text[]", - "primaryKey": false, - "notNull": false, - "default": "'{}'" - }, - "emails": { - "name": "emails", - "type": "text[]", - "primaryKey": false, - "notNull": false, - "default": "'{}'" - }, - "phones": { - "name": "phones", - "type": "text[]", - "primaryKey": false, - "notNull": false, - "default": "'{}'" - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "categories": { - "name": "categories", - "type": "bigint[]", - "primaryKey": false, - "notNull": false, - "default": "'{}'" - }, - "created_by": { - "name": "created_by", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "redirect_url": { - "name": "redirect_url", - "type": "varchar(500)", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "campaigns_created_by_users_id_fk": { - "name": "campaigns_created_by_users_id_fk", - "tableFrom": "campaigns", - "tableTo": "users", - "columnsFrom": [ - "created_by" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.categories": { - "name": "categories", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "bigint", - "primaryKey": true, - "notNull": true, - "identity": { - "type": "always", - "name": "categories_id_seq", - "schema": "public", - "increment": "1", - "startWith": "1", - "minValue": "1", - "maxValue": "9223372036854775807", - "cache": "1", - "cycle": false - } - }, - "title": { - "name": "title", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "image": { - "name": "image", - "type": "varchar(500)", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.payment_methods": { - "name": "payment_methods", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "provider": { - "name": "provider", - "type": "payment_method_provider", - "typeSchema": "public", - "primaryKey": false, - "notNull": true - }, - "params": { - "name": "params", - "type": "jsonb", - "primaryKey": false, - "notNull": true - }, - "status": { - "name": "status", - "type": "payment_method_status", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'active'" - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "owner": { - "name": "owner", - "type": "bigint", - "primaryKey": false, - "notNull": true - } - }, - "indexes": { - "payment_methods_provider_owner_index": { - "name": "payment_methods_provider_owner_index", - "columns": [ - { - "expression": "provider", - "isExpression": false, - "asc": true, - "nulls": "last" - }, - { - "expression": "owner", - "isExpression": false, - "asc": true, - "nulls": "last" - } - ], - "isUnique": true, - "concurrently": false, - "method": "btree", - "with": {} - } - }, - "foreignKeys": { - "payment_methods_owner_users_id_fk": { - "name": "payment_methods_owner_users_id_fk", - "tableFrom": "payment_methods", - "tableTo": "users", - "columnsFrom": [ - "owner" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.payment_transactions": { - "name": "payment_transactions", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "payment_method": { - "name": "payment_method", - "type": "payment_method_provider", - "typeSchema": "public", - "primaryKey": false, - "notNull": true - }, - "status": { - "name": "status", - "type": "transaction_status", - "typeSchema": "public", - "primaryKey": false, - "notNull": true - }, - "external_transaction_id": { - "name": "external_transaction_id", - "type": "varchar(400)", - "primaryKey": false, - "notNull": false - }, - "recorded_at": { - "name": "recorded_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "completed_at": { - "name": "completed_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "cancelled_at": { - "name": "cancelled_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "value": { - "name": "value", - "type": "real", - "primaryKey": false, - "notNull": true - }, - "exchange_rate_snapshot": { - "name": "exchange_rate_snapshot", - "type": "real", - "primaryKey": false, - "notNull": true - }, - "converted_value": { - "name": "converted_value", - "type": "real", - "primaryKey": false, - "notNull": true - }, - "notes": { - "name": "notes", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "currency": { - "name": "currency", - "type": "varchar(10)", - "primaryKey": false, - "notNull": true - }, - "params": { - "name": "params", - "type": "jsonb", - "primaryKey": false, - "notNull": false - }, - "inbound": { - "name": "inbound", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.credit_allocations": { - "name": "credit_allocations", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "exhausted": { - "name": "exhausted", - "type": "real", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "allocated": { - "name": "allocated", - "type": "real", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "status": { - "name": "status", - "type": "credit_allocation_status", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'active'" - }, - "wallet": { - "name": "wallet", - "type": "uuid", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "credit_allocations_wallet_wallets_id_fk": { - "name": "credit_allocations_wallet_wallets_id_fk", - "tableFrom": "credit_allocations", - "tableTo": "wallets", - "columnsFrom": [ - "wallet" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.wallet_transactions": { - "name": "wallet_transactions", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "value": { - "name": "value", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "from": { - "name": "from", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "to": { - "name": "to", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "recorded_at": { - "name": "recorded_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "completed_at": { - "name": "completed_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "cancelled_at": { - "name": "cancelled_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "status": { - "name": "status", - "type": "transaction_status", - "typeSchema": "public", - "primaryKey": false, - "notNull": false, - "default": "'pending'" - }, - "type": { - "name": "type", - "type": "wallet_transaction_type", - "typeSchema": "public", - "primaryKey": false, - "notNull": true - }, - "notes": { - "name": "notes", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "account_transaction": { - "name": "account_transaction", - "type": "uuid", - "primaryKey": false, - "notNull": false - }, - "credit_allocation": { - "name": "credit_allocation", - "type": "uuid", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "wallet_transactions_from_wallets_id_fk": { - "name": "wallet_transactions_from_wallets_id_fk", - "tableFrom": "wallet_transactions", - "tableTo": "wallets", - "columnsFrom": [ - "from" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "wallet_transactions_to_wallets_id_fk": { - "name": "wallet_transactions_to_wallets_id_fk", - "tableFrom": "wallet_transactions", - "tableTo": "wallets", - "columnsFrom": [ - "to" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "wallet_transactions_account_transaction_payment_transactions_id_fk": { - "name": "wallet_transactions_account_transaction_payment_transactions_id_fk", - "tableFrom": "wallet_transactions", - "tableTo": "payment_transactions", - "columnsFrom": [ - "account_transaction" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "wallet_transactions_credit_allocation_credit_allocations_id_fk": { - "name": "wallet_transactions_credit_allocation_credit_allocations_id_fk", - "tableFrom": "wallet_transactions", - "tableTo": "credit_allocations", - "columnsFrom": [ - "credit_allocation" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.wallets": { - "name": "wallets", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "owned_by": { - "name": "owned_by", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "starting_balance": { - "name": "starting_balance", - "type": "bigint", - "primaryKey": false, - "notNull": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "wallets_owned_by_users_id_fk": { - "name": "wallets_owned_by_users_id_fk", - "tableFrom": "wallets", - "tableTo": "users", - "columnsFrom": [ - "owned_by" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.access_tokens": { - "name": "access_tokens", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "ip": { - "name": "ip", - "type": "varchar(39)", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "revoked_at": { - "name": "revoked_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "window": { - "name": "window", - "type": "interval", - "primaryKey": false, - "notNull": true - }, - "user": { - "name": "user", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "replaced_by": { - "name": "replaced_by", - "type": "uuid", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "access_tokens_user_users_id_fk": { - "name": "access_tokens_user_users_id_fk", - "tableFrom": "access_tokens", - "tableTo": "users", - "columnsFrom": [ - "user" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "access_tokens_replaced_by_access_tokens_id_fk": { - "name": "access_tokens_replaced_by_access_tokens_id_fk", - "tableFrom": "access_tokens", - "tableTo": "access_tokens", - "columnsFrom": [ - "replaced_by" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.account_connections": { - "name": "account_connections", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "user": { - "name": "user", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "provider": { - "name": "provider", - "type": "account_connection_providers", - "typeSchema": "public", - "primaryKey": false, - "notNull": true - }, - "params": { - "name": "params", - "type": "jsonb", - "primaryKey": false, - "notNull": true - }, - "status": { - "name": "status", - "type": "account_connection_status", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'active'" - }, - "provider_id": { - "name": "provider_id", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "account_connections_user_users_id_fk": { - "name": "account_connections_user_users_id_fk", - "tableFrom": "account_connections", - "tableTo": "users", - "columnsFrom": [ - "user" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.federated_credentials": { - "name": "federated_credentials", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "varchar(255)", - "primaryKey": true, - "notNull": true - }, - "provider": { - "name": "provider", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "last_access_token": { - "name": "last_access_token", - "type": "varchar(500)", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.refresh_tokens": { - "name": "refresh_tokens", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "token": { - "name": "token", - "type": "varchar(32)", - "primaryKey": false, - "notNull": true - }, - "user": { - "name": "user", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "ip": { - "name": "ip", - "type": "varchar(39)", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "replaced_by": { - "name": "replaced_by", - "type": "uuid", - "primaryKey": false, - "notNull": false - }, - "revoked_by": { - "name": "revoked_by", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "window": { - "name": "window", - "type": "interval", - "primaryKey": false, - "notNull": true - }, - "access_token": { - "name": "access_token", - "type": "uuid", - "primaryKey": false, - "notNull": true - } - }, - "indexes": { - "refresh_tokens_token_user_index": { - "name": "refresh_tokens_token_user_index", - "columns": [ - { - "expression": "token", - "isExpression": false, - "asc": true, - "nulls": "last" - }, - { - "expression": "user", - "isExpression": false, - "asc": true, - "nulls": "last" - } - ], - "isUnique": true, - "concurrently": false, - "method": "btree", - "with": {} - } - }, - "foreignKeys": { - "refresh_tokens_user_users_id_fk": { - "name": "refresh_tokens_user_users_id_fk", - "tableFrom": "refresh_tokens", - "tableTo": "users", - "columnsFrom": [ - "user" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "refresh_tokens_replaced_by_refresh_tokens_id_fk": { - "name": "refresh_tokens_replaced_by_refresh_tokens_id_fk", - "tableFrom": "refresh_tokens", - "tableTo": "refresh_tokens", - "columnsFrom": [ - "replaced_by" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "refresh_tokens_revoked_by_users_id_fk": { - "name": "refresh_tokens_revoked_by_users_id_fk", - "tableFrom": "refresh_tokens", - "tableTo": "users", - "columnsFrom": [ - "revoked_by" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "refresh_tokens_access_token_access_tokens_id_fk": { - "name": "refresh_tokens_access_token_access_tokens_id_fk", - "tableFrom": "refresh_tokens", - "tableTo": "access_tokens", - "columnsFrom": [ - "access_token" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "refresh_tokens_token_unique": { - "name": "refresh_tokens_token_unique", - "nullsNotDistinct": false, - "columns": [ - "token" - ] - } - }, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.user_prefs": { - "name": "user_prefs", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "user": { - "name": "user", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "country": { - "name": "country", - "type": "varchar(2)", - "primaryKey": false, - "notNull": true - }, - "theme": { - "name": "theme", - "type": "theme_pref", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'light'" - }, - "currency": { - "name": "currency", - "type": "varchar(3)", - "primaryKey": false, - "notNull": true - }, - "language": { - "name": "language", - "type": "varchar(2)", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "user_prefs_user_users_id_fk": { - "name": "user_prefs_user_users_id_fk", - "tableFrom": "user_prefs", - "tableTo": "users", - "columnsFrom": [ - "user" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.users": { - "name": "users", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "bigint", - "primaryKey": true, - "notNull": true, - "identity": { - "type": "always", - "name": "users_id_seq", - "schema": "public", - "increment": "1", - "startWith": "100", - "minValue": "1", - "maxValue": "9223372036854775807", - "cache": "1", - "cycle": false - } - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "names": { - "name": "names", - "type": "varchar(100)", - "primaryKey": false, - "notNull": true - }, - "image_url": { - "name": "image_url", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false - }, - "email": { - "name": "email", - "type": "varchar(100)", - "primaryKey": false, - "notNull": true - }, - "dob": { - "name": "dob", - "type": "date", - "primaryKey": false, - "notNull": false - }, - "phone": { - "name": "phone", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false - }, - "credentials": { - "name": "credentials", - "type": "varchar", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "users_credentials_federated_credentials_id_fk": { - "name": "users_credentials_federated_credentials_id_fk", - "tableFrom": "users", - "tableTo": "federated_credentials", - "columnsFrom": [ - "credentials" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.verification_codes": { - "name": "verification_codes", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "window": { - "name": "window", - "type": "interval", - "primaryKey": false, - "notNull": true - }, - "hash": { - "name": "hash", - "type": "varchar(32)", - "primaryKey": false, - "notNull": true - }, - "confirmed_at": { - "name": "confirmed_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "data": { - "name": "data", - "type": "jsonb", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "verification_codes_hash_unique": { - "name": "verification_codes_hash_unique", - "nullsNotDistinct": false, - "columns": [ - "hash" - ] - } - }, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - } - }, - "enums": { - "public.credit_allocation_status": { - "name": "credit_allocation_status", - "schema": "public", - "values": [ - "active", - "cancelled", - "complete" - ] - }, - "public.payment_method_provider": { - "name": "payment_method_provider", - "schema": "public", - "values": [ - "momo", - "virtual" - ] - }, - "public.payment_method_status": { - "name": "payment_method_status", - "schema": "public", - "values": [ - "active", - "inactive", - "re-connection required" - ] - }, - "public.transaction_status": { - "name": "transaction_status", - "schema": "public", - "values": [ - "pending", - "cancelled", - "complete" - ] - }, - "public.wallet_transaction_type": { - "name": "wallet_transaction_type", - "schema": "public", - "values": [ - "funding", - "reward", - "withdrawal" - ] - }, - "public.account_connection_providers": { - "name": "account_connection_providers", - "schema": "public", - "values": [ - "telegram" - ] - }, - "public.account_connection_status": { - "name": "account_connection_status", - "schema": "public", - "values": [ - "active", - "inactive", - "reconnect_required" - ] - }, - "public.theme_pref": { - "name": "theme_pref", - "schema": "public", - "values": [ - "system", - "dark", - "light" - ] - } - }, - "schemas": {}, - "sequences": {}, - "roles": {}, - "policies": {}, - "views": { - "public.vw_funding_balances": { - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "ownedBy": { - "name": "ownedBy", - "type": "bigint", - "primaryKey": false, - "notNull": true - } - }, - "definition": "select \"wallets\".\"id\", \n \"wallets\".\"starting_balance\" +\n SUM(\n CASE\n WHEN \"credit_allocations\".\"status\" = 'active' THEN \"credit_allocations\".\"allocated\"\n ELSE 0\n END\n ) * -1 +\n SUM(\n CASE\n WHEN (\"wallet_transactions\".\"from\" = \"wallets\".\"id\" and \"wallet_transactions\".\"type\" = 'funding' and \"wallet_transactions\".\"status\" = 'complete') THEN -\"wallet_transactions\".\"value\"\n WHEN (\"wallet_transactions\".\"to\" = \"wallets\".\"id\" and \"wallet_transactions\".\"type\" = 'funding' and \"wallet_transactions\".\"status\" = 'complete') THEN \"wallet_transactions\".\"value\"\n ELSE 0\n END\n )::BIGINT as \"balance\", \"wallets\".\"owned_by\" from \"wallets\" left join \"wallet_transactions\" on (\"wallets\".\"id\" = \"wallet_transactions\".\"from\" or \"wallets\".\"id\" = \"wallet_transactions\".\"to\") left join \"users\" on \"wallets\".\"owned_by\" = \"users\".\"id\" left join \"credit_allocations\" on \"wallets\".\"id\" = \"credit_allocations\".\"wallet\" group by \"wallets\".\"id\", \"wallets\".\"owned_by\"", - "name": "vw_funding_balances", - "schema": "public", - "isExisting": false, - "materialized": false - }, - "public.vw_reward_balances": { - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "ownedBy": { - "name": "ownedBy", - "type": "bigint", - "primaryKey": false, - "notNull": true - } - }, - "definition": "select \"wallets\".\"id\", \n SUM(\n CASE\n WHEN (\"wallet_transactions\".\"from\" = \"wallets\".\"id\" and \"wallet_transactions\".\"type\" = 'reward' and \"wallet_transactions\".\"status\" = 'complete') THEN -\"wallet_transactions\".\"value\"\n WHEN (\"wallet_transactions\".\"to\" = \"wallets\".\"id\" and \"wallet_transactions\".\"type\" = 'reward' and \"wallet_transactions\".\"status\" = 'complete') THEN \"wallet_transactions\".\"value\"\n ELSE 0\n END\n )::BIGINT as \"balance\", \"wallets\".\"owned_by\" from \"wallets\" left join \"wallet_transactions\" on (\"wallets\".\"id\" = \"wallet_transactions\".\"from\" or \"wallets\".\"id\" = \"wallet_transactions\".\"to\") left join \"users\" on \"wallets\".\"owned_by\" = \"users\".\"id\" group by \"wallets\".\"id\", \"wallets\".\"owned_by\"", - "name": "vw_reward_balances", - "schema": "public", - "isExisting": false, - "materialized": false - }, - "public.vw_credit_allocations": { - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "wallet": { - "name": "wallet", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "allocated": { - "name": "allocated", - "type": "real", - "primaryKey": false, - "notNull": true - } - }, - "definition": "select \"credit_allocations\".\"id\", \"credit_allocations\".\"wallet\", \"credit_allocations\".\"allocated\", \n COALESCE(SUM(\"wallet_transactions\".\"value\"), 0)\n as \"exhausted\" from \"credit_allocations\" left join \"wallet_transactions\" on (\"credit_allocations\".\"id\" = \"wallet_transactions\".\"credit_allocation\" and \"wallet_transactions\".\"type\" = 'reward' and \"wallet_transactions\".\"from\" = \"credit_allocations\".\"wallet\") group by \"credit_allocations\".\"id\"", - "name": "vw_credit_allocations", - "schema": "public", - "isExisting": false, - "materialized": false - }, - "public.vw_verification_codes": { - "columns": { - "hash": { - "name": "hash", - "type": "varchar(32)", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "data": { - "name": "data", - "type": "jsonb", - "primaryKey": false, - "notNull": false - } - }, - "definition": "select \"hash\", \"created_at\", \n (\"created_at\" + \"window\")::TIMESTAMP\n as \"expires_at\", \n (CASE\n WHEN \"confirmed_at\" IS NOT NULL THEN true\n ELSE NOW() > (\"created_at\" + \"window\")\n END)::BOOlEAN\n as \"is_expired\", \"data\" from \"verification_codes\"", - "name": "vw_verification_codes", - "schema": "public", - "isExisting": false, - "materialized": false - }, - "public.vw_access_tokens": { - "columns": { - "user": { - "name": "user", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "ip": { - "name": "ip", - "type": "varchar(39)", - "primaryKey": false, - "notNull": true - }, - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - } - }, - "definition": "select \"user\", (now() > (\"created_at\" + \"window\")::TIMESTAMP)::BOOLEAN OR revoked_at IS NOT NULL OR replaced_by IS NOT NULL as \"is_expired\", (created_at + \"window\")::TIMESTAMP as \"expires_at\", \"created_at\", \"ip\", \"id\" from \"access_tokens\"", - "name": "vw_access_tokens", - "schema": "public", - "isExisting": false, - "materialized": false - }, - "public.vw_refresh_tokens": { - "columns": { - "revoked_by": { - "name": "revoked_by", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "replaced_by": { - "name": "replaced_by", - "type": "uuid", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "access_token": { - "name": "access_token", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "ip": { - "name": "ip", - "type": "varchar(39)", - "primaryKey": false, - "notNull": true - }, - "user": { - "name": "user", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "token": { - "name": "token", - "type": "varchar(32)", - "primaryKey": false, - "notNull": true - }, - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - } - }, - "definition": "select (now()::TIMESTAMP > (\"created_at\" + \"window\")::TIMESTAMP)::BOOLEAN OR \"revoked_by\" IS NOT NULL as \"is_expired\", (\"created_at\" + \"window\")::TIMESTAMP as \"expires\", \"revoked_by\", \"replaced_by\", \"created_at\", \"access_token\", \"ip\", \"user\", \"token\", \"id\" from \"refresh_tokens\"", - "name": "vw_refresh_tokens", - "schema": "public", - "isExisting": false, - "materialized": false - } - }, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/db/migrations/meta/0003_snapshot.json b/db/migrations/meta/0003_snapshot.json deleted file mode 100644 index c9122f0..0000000 --- a/db/migrations/meta/0003_snapshot.json +++ /dev/null @@ -1,1617 +0,0 @@ -{ - "id": "9ba43aa8-3090-4234-8035-daa876dd6e6e", - "prevId": "fb1a4aac-1e52-434f-9a05-f9f8158d857d", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.campaign_publications": { - "name": "campaign_publications", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "bigint", - "primaryKey": true, - "notNull": true, - "identity": { - "type": "always", - "name": "campaign_publications_id_seq", - "schema": "public", - "increment": "1", - "startWith": "1", - "minValue": "1", - "maxValue": "9223372036854775807", - "cache": "1", - "cycle": false - } - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "campaign": { - "name": "campaign", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "credit_allocation": { - "name": "credit_allocation", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "publish_after": { - "name": "publish_after", - "type": "date", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "publish_before": { - "name": "publish_before", - "type": "date", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "campaign_publications_campaign_campaigns_id_fk": { - "name": "campaign_publications_campaign_campaigns_id_fk", - "tableFrom": "campaign_publications", - "tableTo": "campaigns", - "columnsFrom": [ - "campaign" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "campaign_publications_credit_allocation_credit_allocations_id_fk": { - "name": "campaign_publications_credit_allocation_credit_allocations_id_fk", - "tableFrom": "campaign_publications", - "tableTo": "credit_allocations", - "columnsFrom": [ - "credit_allocation" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.campaigns": { - "name": "campaigns", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "bigint", - "primaryKey": true, - "notNull": true, - "identity": { - "type": "always", - "name": "campaigns_id_seq", - "schema": "public", - "increment": "1", - "startWith": "1", - "minValue": "1", - "maxValue": "9223372036854775807", - "cache": "1", - "cycle": false - } - }, - "title": { - "name": "title", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "media": { - "name": "media", - "type": "text[]", - "primaryKey": false, - "notNull": false, - "default": "'{}'" - }, - "links": { - "name": "links", - "type": "text[]", - "primaryKey": false, - "notNull": false, - "default": "'{}'" - }, - "emails": { - "name": "emails", - "type": "text[]", - "primaryKey": false, - "notNull": false, - "default": "'{}'" - }, - "phones": { - "name": "phones", - "type": "text[]", - "primaryKey": false, - "notNull": false, - "default": "'{}'" - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "categories": { - "name": "categories", - "type": "bigint[]", - "primaryKey": false, - "notNull": false, - "default": "'{}'" - }, - "created_by": { - "name": "created_by", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "redirect_url": { - "name": "redirect_url", - "type": "varchar(500)", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "campaigns_created_by_users_id_fk": { - "name": "campaigns_created_by_users_id_fk", - "tableFrom": "campaigns", - "tableTo": "users", - "columnsFrom": [ - "created_by" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.categories": { - "name": "categories", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "bigint", - "primaryKey": true, - "notNull": true, - "identity": { - "type": "always", - "name": "categories_id_seq", - "schema": "public", - "increment": "1", - "startWith": "1", - "minValue": "1", - "maxValue": "9223372036854775807", - "cache": "1", - "cycle": false - } - }, - "title": { - "name": "title", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "image": { - "name": "image", - "type": "varchar(500)", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.payment_methods": { - "name": "payment_methods", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "provider": { - "name": "provider", - "type": "payment_method_provider", - "typeSchema": "public", - "primaryKey": false, - "notNull": true - }, - "params": { - "name": "params", - "type": "jsonb", - "primaryKey": false, - "notNull": true - }, - "status": { - "name": "status", - "type": "payment_method_status", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'active'" - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "owner": { - "name": "owner", - "type": "bigint", - "primaryKey": false, - "notNull": true - } - }, - "indexes": { - "payment_methods_provider_owner_index": { - "name": "payment_methods_provider_owner_index", - "columns": [ - { - "expression": "provider", - "isExpression": false, - "asc": true, - "nulls": "last" - }, - { - "expression": "owner", - "isExpression": false, - "asc": true, - "nulls": "last" - } - ], - "isUnique": true, - "concurrently": false, - "method": "btree", - "with": {} - } - }, - "foreignKeys": { - "payment_methods_owner_users_id_fk": { - "name": "payment_methods_owner_users_id_fk", - "tableFrom": "payment_methods", - "tableTo": "users", - "columnsFrom": [ - "owner" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.payment_transactions": { - "name": "payment_transactions", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "payment_method": { - "name": "payment_method", - "type": "payment_method_provider", - "typeSchema": "public", - "primaryKey": false, - "notNull": true - }, - "status": { - "name": "status", - "type": "transaction_status", - "typeSchema": "public", - "primaryKey": false, - "notNull": true - }, - "external_transaction_id": { - "name": "external_transaction_id", - "type": "varchar(400)", - "primaryKey": false, - "notNull": false - }, - "recorded_at": { - "name": "recorded_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "completed_at": { - "name": "completed_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "cancelled_at": { - "name": "cancelled_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "value": { - "name": "value", - "type": "real", - "primaryKey": false, - "notNull": true - }, - "exchange_rate_snapshot": { - "name": "exchange_rate_snapshot", - "type": "real", - "primaryKey": false, - "notNull": true - }, - "converted_value": { - "name": "converted_value", - "type": "real", - "primaryKey": false, - "notNull": true - }, - "notes": { - "name": "notes", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "currency": { - "name": "currency", - "type": "varchar(10)", - "primaryKey": false, - "notNull": true - }, - "params": { - "name": "params", - "type": "jsonb", - "primaryKey": false, - "notNull": false - }, - "inbound": { - "name": "inbound", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.credit_allocations": { - "name": "credit_allocations", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "exhausted": { - "name": "exhausted", - "type": "real", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "allocated": { - "name": "allocated", - "type": "real", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "status": { - "name": "status", - "type": "credit_allocation_status", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'active'" - }, - "wallet": { - "name": "wallet", - "type": "uuid", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "credit_allocations_wallet_wallets_id_fk": { - "name": "credit_allocations_wallet_wallets_id_fk", - "tableFrom": "credit_allocations", - "tableTo": "wallets", - "columnsFrom": [ - "wallet" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.wallet_transactions": { - "name": "wallet_transactions", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "value": { - "name": "value", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "from": { - "name": "from", - "type": "uuid", - "primaryKey": false, - "notNull": false - }, - "to": { - "name": "to", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "recorded_at": { - "name": "recorded_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "completed_at": { - "name": "completed_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "cancelled_at": { - "name": "cancelled_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "status": { - "name": "status", - "type": "transaction_status", - "typeSchema": "public", - "primaryKey": false, - "notNull": false, - "default": "'pending'" - }, - "type": { - "name": "type", - "type": "wallet_transaction_type", - "typeSchema": "public", - "primaryKey": false, - "notNull": true - }, - "notes": { - "name": "notes", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "account_transaction": { - "name": "account_transaction", - "type": "uuid", - "primaryKey": false, - "notNull": false - }, - "credit_allocation": { - "name": "credit_allocation", - "type": "uuid", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "wallet_transactions_from_wallets_id_fk": { - "name": "wallet_transactions_from_wallets_id_fk", - "tableFrom": "wallet_transactions", - "tableTo": "wallets", - "columnsFrom": [ - "from" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "wallet_transactions_to_wallets_id_fk": { - "name": "wallet_transactions_to_wallets_id_fk", - "tableFrom": "wallet_transactions", - "tableTo": "wallets", - "columnsFrom": [ - "to" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "wallet_transactions_account_transaction_payment_transactions_id_fk": { - "name": "wallet_transactions_account_transaction_payment_transactions_id_fk", - "tableFrom": "wallet_transactions", - "tableTo": "payment_transactions", - "columnsFrom": [ - "account_transaction" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "wallet_transactions_credit_allocation_credit_allocations_id_fk": { - "name": "wallet_transactions_credit_allocation_credit_allocations_id_fk", - "tableFrom": "wallet_transactions", - "tableTo": "credit_allocations", - "columnsFrom": [ - "credit_allocation" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.wallets": { - "name": "wallets", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "owned_by": { - "name": "owned_by", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "starting_balance": { - "name": "starting_balance", - "type": "bigint", - "primaryKey": false, - "notNull": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "wallets_owned_by_users_id_fk": { - "name": "wallets_owned_by_users_id_fk", - "tableFrom": "wallets", - "tableTo": "users", - "columnsFrom": [ - "owned_by" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.access_tokens": { - "name": "access_tokens", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "ip": { - "name": "ip", - "type": "varchar(39)", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "revoked_at": { - "name": "revoked_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "window": { - "name": "window", - "type": "interval", - "primaryKey": false, - "notNull": true - }, - "user": { - "name": "user", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "replaced_by": { - "name": "replaced_by", - "type": "uuid", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "access_tokens_user_users_id_fk": { - "name": "access_tokens_user_users_id_fk", - "tableFrom": "access_tokens", - "tableTo": "users", - "columnsFrom": [ - "user" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "access_tokens_replaced_by_access_tokens_id_fk": { - "name": "access_tokens_replaced_by_access_tokens_id_fk", - "tableFrom": "access_tokens", - "tableTo": "access_tokens", - "columnsFrom": [ - "replaced_by" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.account_connections": { - "name": "account_connections", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "user": { - "name": "user", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "provider": { - "name": "provider", - "type": "account_connection_providers", - "typeSchema": "public", - "primaryKey": false, - "notNull": true - }, - "params": { - "name": "params", - "type": "jsonb", - "primaryKey": false, - "notNull": true - }, - "status": { - "name": "status", - "type": "account_connection_status", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'active'" - }, - "provider_id": { - "name": "provider_id", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "account_connections_user_users_id_fk": { - "name": "account_connections_user_users_id_fk", - "tableFrom": "account_connections", - "tableTo": "users", - "columnsFrom": [ - "user" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.federated_credentials": { - "name": "federated_credentials", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "varchar(255)", - "primaryKey": true, - "notNull": true - }, - "provider": { - "name": "provider", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "last_access_token": { - "name": "last_access_token", - "type": "varchar(500)", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.refresh_tokens": { - "name": "refresh_tokens", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "token": { - "name": "token", - "type": "varchar(32)", - "primaryKey": false, - "notNull": true - }, - "user": { - "name": "user", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "ip": { - "name": "ip", - "type": "varchar(39)", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "replaced_by": { - "name": "replaced_by", - "type": "uuid", - "primaryKey": false, - "notNull": false - }, - "revoked_by": { - "name": "revoked_by", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "window": { - "name": "window", - "type": "interval", - "primaryKey": false, - "notNull": true - }, - "access_token": { - "name": "access_token", - "type": "uuid", - "primaryKey": false, - "notNull": true - } - }, - "indexes": { - "refresh_tokens_token_user_index": { - "name": "refresh_tokens_token_user_index", - "columns": [ - { - "expression": "token", - "isExpression": false, - "asc": true, - "nulls": "last" - }, - { - "expression": "user", - "isExpression": false, - "asc": true, - "nulls": "last" - } - ], - "isUnique": true, - "concurrently": false, - "method": "btree", - "with": {} - } - }, - "foreignKeys": { - "refresh_tokens_user_users_id_fk": { - "name": "refresh_tokens_user_users_id_fk", - "tableFrom": "refresh_tokens", - "tableTo": "users", - "columnsFrom": [ - "user" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "refresh_tokens_replaced_by_refresh_tokens_id_fk": { - "name": "refresh_tokens_replaced_by_refresh_tokens_id_fk", - "tableFrom": "refresh_tokens", - "tableTo": "refresh_tokens", - "columnsFrom": [ - "replaced_by" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "refresh_tokens_revoked_by_users_id_fk": { - "name": "refresh_tokens_revoked_by_users_id_fk", - "tableFrom": "refresh_tokens", - "tableTo": "users", - "columnsFrom": [ - "revoked_by" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "refresh_tokens_access_token_access_tokens_id_fk": { - "name": "refresh_tokens_access_token_access_tokens_id_fk", - "tableFrom": "refresh_tokens", - "tableTo": "access_tokens", - "columnsFrom": [ - "access_token" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "refresh_tokens_token_unique": { - "name": "refresh_tokens_token_unique", - "nullsNotDistinct": false, - "columns": [ - "token" - ] - } - }, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.user_prefs": { - "name": "user_prefs", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "user": { - "name": "user", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "country": { - "name": "country", - "type": "varchar(2)", - "primaryKey": false, - "notNull": true - }, - "theme": { - "name": "theme", - "type": "theme_pref", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'light'" - }, - "currency": { - "name": "currency", - "type": "varchar(3)", - "primaryKey": false, - "notNull": true - }, - "language": { - "name": "language", - "type": "varchar(2)", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "user_prefs_user_users_id_fk": { - "name": "user_prefs_user_users_id_fk", - "tableFrom": "user_prefs", - "tableTo": "users", - "columnsFrom": [ - "user" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.users": { - "name": "users", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "bigint", - "primaryKey": true, - "notNull": true, - "identity": { - "type": "always", - "name": "users_id_seq", - "schema": "public", - "increment": "1", - "startWith": "100", - "minValue": "1", - "maxValue": "9223372036854775807", - "cache": "1", - "cycle": false - } - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "default": "now()" - }, - "names": { - "name": "names", - "type": "varchar(100)", - "primaryKey": false, - "notNull": true - }, - "image_url": { - "name": "image_url", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false - }, - "email": { - "name": "email", - "type": "varchar(100)", - "primaryKey": false, - "notNull": true - }, - "dob": { - "name": "dob", - "type": "date", - "primaryKey": false, - "notNull": false - }, - "phone": { - "name": "phone", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false - }, - "credentials": { - "name": "credentials", - "type": "varchar", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "users_credentials_federated_credentials_id_fk": { - "name": "users_credentials_federated_credentials_id_fk", - "tableFrom": "users", - "tableTo": "federated_credentials", - "columnsFrom": [ - "credentials" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.verification_codes": { - "name": "verification_codes", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "window": { - "name": "window", - "type": "interval", - "primaryKey": false, - "notNull": true - }, - "hash": { - "name": "hash", - "type": "varchar(32)", - "primaryKey": false, - "notNull": true - }, - "confirmed_at": { - "name": "confirmed_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "data": { - "name": "data", - "type": "jsonb", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "verification_codes_hash_unique": { - "name": "verification_codes_hash_unique", - "nullsNotDistinct": false, - "columns": [ - "hash" - ] - } - }, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - } - }, - "enums": { - "public.credit_allocation_status": { - "name": "credit_allocation_status", - "schema": "public", - "values": [ - "active", - "cancelled", - "complete" - ] - }, - "public.payment_method_provider": { - "name": "payment_method_provider", - "schema": "public", - "values": [ - "momo", - "virtual" - ] - }, - "public.payment_method_status": { - "name": "payment_method_status", - "schema": "public", - "values": [ - "active", - "inactive", - "re-connection required" - ] - }, - "public.transaction_status": { - "name": "transaction_status", - "schema": "public", - "values": [ - "pending", - "cancelled", - "complete" - ] - }, - "public.wallet_transaction_type": { - "name": "wallet_transaction_type", - "schema": "public", - "values": [ - "funding", - "reward", - "withdrawal" - ] - }, - "public.account_connection_providers": { - "name": "account_connection_providers", - "schema": "public", - "values": [ - "telegram" - ] - }, - "public.account_connection_status": { - "name": "account_connection_status", - "schema": "public", - "values": [ - "active", - "inactive", - "reconnect_required" - ] - }, - "public.theme_pref": { - "name": "theme_pref", - "schema": "public", - "values": [ - "system", - "dark", - "light" - ] - } - }, - "schemas": {}, - "sequences": {}, - "roles": {}, - "policies": {}, - "views": { - "public.vw_funding_balances": { - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "ownedBy": { - "name": "ownedBy", - "type": "bigint", - "primaryKey": false, - "notNull": true - } - }, - "definition": "select \"wallets\".\"id\", \n \"wallets\".\"starting_balance\" +\n SUM(\n CASE\n WHEN \"credit_allocations\".\"status\" = 'active' THEN \"credit_allocations\".\"allocated\"\n ELSE 0\n END\n ) * -1 +\n SUM(\n CASE\n WHEN (\"wallet_transactions\".\"from\" = \"wallets\".\"id\" and \"wallet_transactions\".\"type\" = 'funding' and \"wallet_transactions\".\"status\" = 'complete') THEN -\"wallet_transactions\".\"value\"\n WHEN (\"wallet_transactions\".\"to\" = \"wallets\".\"id\" and \"wallet_transactions\".\"type\" = 'funding' and \"wallet_transactions\".\"status\" = 'complete') THEN \"wallet_transactions\".\"value\"\n ELSE 0\n END\n )::BIGINT as \"balance\", \"wallets\".\"owned_by\" from \"wallets\" left join \"wallet_transactions\" on (\"wallets\".\"id\" = \"wallet_transactions\".\"from\" or \"wallets\".\"id\" = \"wallet_transactions\".\"to\") left join \"users\" on \"wallets\".\"owned_by\" = \"users\".\"id\" left join \"credit_allocations\" on \"wallets\".\"id\" = \"credit_allocations\".\"wallet\" group by \"wallets\".\"id\", \"wallets\".\"owned_by\"", - "name": "vw_funding_balances", - "schema": "public", - "isExisting": false, - "materialized": false - }, - "public.vw_reward_balances": { - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "ownedBy": { - "name": "ownedBy", - "type": "bigint", - "primaryKey": false, - "notNull": true - } - }, - "definition": "select \"wallets\".\"id\", \n SUM(\n CASE\n WHEN (\"wallet_transactions\".\"from\" = \"wallets\".\"id\" and \"wallet_transactions\".\"type\" = 'reward' and \"wallet_transactions\".\"status\" = 'complete') THEN -\"wallet_transactions\".\"value\"\n WHEN (\"wallet_transactions\".\"to\" = \"wallets\".\"id\" and \"wallet_transactions\".\"type\" = 'reward' and \"wallet_transactions\".\"status\" = 'complete') THEN \"wallet_transactions\".\"value\"\n ELSE 0\n END\n )::BIGINT as \"balance\", \"wallets\".\"owned_by\" from \"wallets\" left join \"wallet_transactions\" on (\"wallets\".\"id\" = \"wallet_transactions\".\"from\" or \"wallets\".\"id\" = \"wallet_transactions\".\"to\") left join \"users\" on \"wallets\".\"owned_by\" = \"users\".\"id\" group by \"wallets\".\"id\", \"wallets\".\"owned_by\"", - "name": "vw_reward_balances", - "schema": "public", - "isExisting": false, - "materialized": false - }, - "public.vw_credit_allocations": { - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "wallet": { - "name": "wallet", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "allocated": { - "name": "allocated", - "type": "real", - "primaryKey": false, - "notNull": true - } - }, - "definition": "select \"credit_allocations\".\"id\", \"credit_allocations\".\"wallet\", \"credit_allocations\".\"allocated\", \n COALESCE(SUM(\"wallet_transactions\".\"value\"), 0)\n as \"exhausted\" from \"credit_allocations\" left join \"wallet_transactions\" on (\"credit_allocations\".\"id\" = \"wallet_transactions\".\"credit_allocation\" and \"wallet_transactions\".\"type\" = 'reward' and \"wallet_transactions\".\"from\" = \"credit_allocations\".\"wallet\") group by \"credit_allocations\".\"id\"", - "name": "vw_credit_allocations", - "schema": "public", - "isExisting": false, - "materialized": false - }, - "public.vw_verification_codes": { - "columns": { - "hash": { - "name": "hash", - "type": "varchar(32)", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "data": { - "name": "data", - "type": "jsonb", - "primaryKey": false, - "notNull": false - } - }, - "definition": "select \"hash\", \"created_at\", \n (\"created_at\" + \"window\")::TIMESTAMP\n as \"expires_at\", \n (CASE\n WHEN \"confirmed_at\" IS NOT NULL THEN true\n ELSE NOW() > (\"created_at\" + \"window\")\n END)::BOOlEAN\n as \"is_expired\", \"data\" from \"verification_codes\"", - "name": "vw_verification_codes", - "schema": "public", - "isExisting": false, - "materialized": false - }, - "public.vw_access_tokens": { - "columns": { - "user": { - "name": "user", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "ip": { - "name": "ip", - "type": "varchar(39)", - "primaryKey": false, - "notNull": true - }, - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - } - }, - "definition": "select \"user\", (now() > (\"created_at\" + \"window\")::TIMESTAMP)::BOOLEAN OR revoked_at IS NOT NULL OR replaced_by IS NOT NULL as \"is_expired\", (created_at + \"window\")::TIMESTAMP as \"expires_at\", \"created_at\", \"ip\", \"id\" from \"access_tokens\"", - "name": "vw_access_tokens", - "schema": "public", - "isExisting": false, - "materialized": false - }, - "public.vw_refresh_tokens": { - "columns": { - "revoked_by": { - "name": "revoked_by", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "replaced_by": { - "name": "replaced_by", - "type": "uuid", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "access_token": { - "name": "access_token", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "ip": { - "name": "ip", - "type": "varchar(39)", - "primaryKey": false, - "notNull": true - }, - "user": { - "name": "user", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "token": { - "name": "token", - "type": "varchar(32)", - "primaryKey": false, - "notNull": true - }, - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - } - }, - "definition": "select (now()::TIMESTAMP > (\"created_at\" + \"window\")::TIMESTAMP)::BOOLEAN OR \"revoked_by\" IS NOT NULL as \"is_expired\", (\"created_at\" + \"window\")::TIMESTAMP as \"expires\", \"revoked_by\", \"replaced_by\", \"created_at\", \"access_token\", \"ip\", \"user\", \"token\", \"id\" from \"refresh_tokens\"", - "name": "vw_refresh_tokens", - "schema": "public", - "isExisting": false, - "materialized": false - } - }, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/db/migrations/meta/_journal.json b/db/migrations/meta/_journal.json index 3b46812..8fa656b 100644 --- a/db/migrations/meta/_journal.json +++ b/db/migrations/meta/_journal.json @@ -5,29 +5,8 @@ { "idx": 0, "version": "7", - "when": 1737269652579, - "tag": "0000_melted_imperial_guard", - "breakpoints": true - }, - { - "idx": 1, - "version": "7", - "when": 1737307129025, - "tag": "0001_panoramic_namora", - "breakpoints": true - }, - { - "idx": 2, - "version": "7", - "when": 1737307194352, - "tag": "0002_ambitious_spirit", - "breakpoints": true - }, - { - "idx": 3, - "version": "7", - "when": 1737309892074, - "tag": "0003_ancient_storm", + "when": 1737462973413, + "tag": "0000_breezy_surge", "breakpoints": true } ] diff --git a/db/schema/finance.ts b/db/schema/finance.ts index e38d1a9..dfb4a08 100644 --- a/db/schema/finance.ts +++ b/db/schema/finance.ts @@ -1,4 +1,4 @@ -import { and, eq, or, sql } from 'drizzle-orm'; +import { and, eq, or, sql, sum } from 'drizzle-orm'; import { bigint, boolean, @@ -59,8 +59,7 @@ export const walletTransactions = pgTable('wallet_transactions', { export const creditAllocationStatus = pgEnum('credit_allocation_status', ['active', 'cancelled', 'complete']); export const walletCreditAllocations = pgTable('credit_allocations', { id: uuid().primaryKey().defaultRandom(), - exhausted: real().notNull().default(0), - allocated: real().notNull(), + allocated: bigint({ mode: 'number' }).notNull(), createdAt: timestamp({ mode: 'date' }).defaultNow(), updatedAt: timestamp({ mode: 'date' }).defaultNow(), status: creditAllocationStatus().notNull().default('active'), @@ -85,30 +84,46 @@ export const paymentTransactions = pgTable('payment_transactions', { }); export const fundingBalances = pgView('vw_funding_balances') - .as(qb => qb.select({ - id: wallets.id, - balance: sql` - ${wallets.startingBalance} + - SUM( - CASE - WHEN ${eq(walletCreditAllocations.status, 'active')} THEN ${walletCreditAllocations.allocated} - ELSE 0 - END - ) * -1 + - SUM( - CASE - WHEN ${and(eq(walletTransactions.from, wallets.id), eq(walletTransactions.type, 'funding'), eq(walletTransactions.status, 'complete'))} THEN -${walletTransactions.value} - WHEN ${and(eq(walletTransactions.to, wallets.id), eq(walletTransactions.type, 'funding'), eq(walletTransactions.status, 'complete'))} THEN ${walletTransactions.value} - ELSE 0 - END - )::BIGINT`.as('balance'), - ownerId: wallets.ownedBy - }).from(wallets) - .leftJoin(walletTransactions, (wallet) => or(eq(wallet.id, walletTransactions.from), eq(wallet.id, walletTransactions.to))) - .leftJoin(users, (wallet) => eq(wallet.ownerId, users.id)) - .leftJoin(walletCreditAllocations, (wallet) => eq(wallet.id, walletCreditAllocations.wallet)) - .groupBy(wallets.id, wallets.ownedBy) - ); + .as(qb => { + const incomingTransactions = qb.select({ + walletId: walletTransactions.to, + totalIncoming: sql`COALESCE(SUM(${walletTransactions.value}), 0)`.as('total_incoming') + }) + .from(walletTransactions) + .where(eq(walletTransactions.status, 'complete')) + .groupBy(walletTransactions.to) + .as('incoming_transactions'); + + const outgoingTransactions = qb.select({ + walletId: walletTransactions.from, + totalOutgoing: sql`COALESCE(SUM(${walletTransactions.value}), 0)`.as('total_outgoing') + }).from(walletTransactions) + .where(eq(walletTransactions.status, 'complete')) + .groupBy(walletTransactions.from) + .as('outgoing_transactions'); + + const allocationSummary = qb.select({ + walletId: walletCreditAllocations.wallet, + totalAllocated: sql`COALESCE(SUM(${walletCreditAllocations.allocated}), 0)`.as('total_allocated') + }).from(walletCreditAllocations) + .where(eq(walletCreditAllocations.status, 'active')) + .groupBy(walletCreditAllocations.wallet) + .as('allocation_summary'); + + return qb.select({ + id: wallets.id, + ownerId: wallets.ownedBy, + balance: sql` + ${wallets.startingBalance} - + COALESCE(${allocationSummary.totalAllocated},0) - + COALESCE(${outgoingTransactions.totalOutgoing},0) + + COALESCE(${incomingTransactions.totalIncoming},0) + `.as('balance') + }).from(wallets) + .leftJoin(incomingTransactions, w => eq(incomingTransactions.walletId, w.id)) + .leftJoin(outgoingTransactions, w => eq(outgoingTransactions.walletId, w.id)) + .leftJoin(allocationSummary, w => eq(allocationSummary.walletId, w.id)) + }); export const rewardBalances = pgView('vw_reward_balances') .as(qb => qb.select({ @@ -135,7 +150,12 @@ export const vwCreditAllocations = pgView('vw_credit_allocations').as( wallet: walletCreditAllocations.wallet, allocated: walletCreditAllocations.allocated, exhausted: sql` - COALESCE(SUM(${walletTransactions.value}), 0) + SUM( + CASE + WHEN ${and(eq(walletTransactions.type, 'reward'), eq(walletTransactions.from, walletCreditAllocations.wallet))} THEN ${walletTransactions.value} + ELSE 0 + END + ) `.as('exhausted') }) .from(walletCreditAllocations) diff --git a/db/seed/users.ts b/db/seed/users.ts index f32dd95..4e4fb38 100644 --- a/db/seed/users.ts +++ b/db/seed/users.ts @@ -1,12 +1,16 @@ -import { useUsersDb } from "@helpers/db.mjs"; -import { users } from "../schema/users"; -import { sql } from "drizzle-orm"; import { PgTransaction } from "drizzle-orm/pg-core"; +import { users } from "../schema/users"; export const name = 'users'; export async function seed(t: PgTransaction) { const systemUserId = 1; - const db = useUsersDb(); - await t.execute(sql`INSERT INTO ${users}(id,names,email) OVERRIDING SYSTEM VALUE VALUES (${systemUserId},${'System'},${'support@tellthem.netlify.app'}) ON CONFLICT (id) DO NOTHING`); - + await t.insert(users) + .overridingSystemValue() + .values({ + id: systemUserId, + names: 'System', + email: 'support@tellthem.netlify.app' + }).onConflictDoNothing({ + target: [users.id] + }); } diff --git a/db/seed/wallets.ts b/db/seed/wallets.ts index f649a82..85749ac 100644 --- a/db/seed/wallets.ts +++ b/db/seed/wallets.ts @@ -6,7 +6,14 @@ export async function seed(t: PgTransaction) { const walletId = String(process.env['SYSTEM_WALLET']); const systemId = 1; const startingBalance = Number(process.env['SYSTEM_STARTING_BALANCE']) - await t.execute(sql`INSERT INTO ${wallets}(id,owned_by,starting_balance) VALUES (${walletId},${systemId},${startingBalance}) ON CONFLICT (id) DO NOTHING`); + // await t.execute(sql`INSERT INTO ${wallets} (id,ownedBy,startingBalance) VALUES (${walletId},${systemId},${startingBalance}) ON CONFLICT (id) DO NOTHING`); + await t.insert(wallets).values({ + ownedBy: systemId, + id: walletId, + startingBalance + }).onConflictDoNothing({ + target: [wallets.id] + }); } export const name = 'wallets'; diff --git a/drizzle.config.ts b/drizzle.config.ts index d18cda4..6dee00c 100644 --- a/drizzle.config.ts +++ b/drizzle.config.ts @@ -4,7 +4,6 @@ const config = defineConfig({ dialect: 'postgresql', out: 'db/migrations', schema: 'db/schema', - casing: 'snake_case', dbCredentials: { url: String(process.env['DATABASE_URL']), } diff --git a/server/handlers/campaign.mts b/server/handlers/campaign.mts index 4079647..1ba8517 100644 --- a/server/handlers/campaign.mts +++ b/server/handlers/campaign.mts @@ -6,7 +6,7 @@ import { useLogger } from '@logger/common'; import { CampaignLookupSchema, campaignPublications, campaigns, newCampaignSchema, newPublicationSchema, updateCampaignSchema } from '@schemas/campaigns'; import { fundingBalances, vwCreditAllocations, walletCreditAllocations } from '@schemas/finance'; import { CampaignIdExtractorSchema, CampaignLookupPaginationValidationSchema } from '@zod-schemas/campaigns.mjs'; -import { and, count, desc, eq } from 'drizzle-orm'; +import { and, count, desc, eq, inArray } from 'drizzle-orm'; import express from 'express'; import { z } from 'zod'; import { fromZodError } from 'zod-validation-error'; @@ -29,7 +29,10 @@ export async function deleteCampaign(req: express.Request, res: express.Response const user = extractUser(req); const db = useCampaignsDb(); await db.transaction(async t => { - await t.delete(campaignPublications).where(eq(campaignPublications.campaign, campaign)); + const publications = await t.select({ id: campaignPublications.id, allocation: campaignPublications.creditAllocation }).from(campaignPublications).where(eq(campaignPublications.campaign, campaign)); + + await t.delete(walletCreditAllocations).where(inArray(walletCreditAllocations.id, publications.map(({ allocation }) => allocation))); + await t.delete(campaignPublications).where(inArray(campaignPublications.id, publications.map(({ id }) => id))); await t.delete(campaigns).where(and(eq(campaigns.id, campaign), eq(campaigns.createdBy, user.id))); }); res.status(200).json({}); diff --git a/server/helpers/db.mts b/server/helpers/db.mts index d685851..7f6445c 100644 --- a/server/helpers/db.mts +++ b/server/helpers/db.mts @@ -1,40 +1,39 @@ -import { neonConfig } from '@neondatabase/serverless'; -import * as campaigns from '@schemas/campaigns'; -import * as categories from '@schemas/categories'; -import * as finance from '@schemas/finance'; -import * as users from '@schemas/users'; +import { neonConfig } from '@neondatabase/serverless'; +import * as campaigns from '@schemas/campaigns'; +import * as categories from '@schemas/categories'; +import * as finance from '@schemas/finance'; +import * as users from '@schemas/users'; import { DefaultLogger } from 'drizzle-orm/logger'; -import { drizzle } from 'drizzle-orm/neon-serverless'; -import ws from 'ws'; +import { drizzle } from 'drizzle-orm/neon-serverless'; +import ws from 'ws'; import { DefaultWriter } from '../../db/log-writer'; neonConfig.webSocketConstructor = global.WebSocket ?? ws; const connection = String(process.env['DATABASE_URL']); -const casing = 'snake_case'; const logger = new DefaultLogger({ writer: new DefaultWriter() }); export function useFinanceDb() { return drizzle({ - schema: { ...finance }, casing, connection, logger + schema: { ...finance }, connection, logger }); } export function useUsersDb() { return drizzle({ - schema: { ...users }, casing, connection, logger + schema: { ...users }, connection, logger }) } export function useCategoriesDb() { return drizzle({ - schema: { ...categories }, casing, connection, logger + schema: { ...categories }, connection, logger }) } export function useCampaignsDb() { return drizzle({ - schema: { ...campaigns }, casing, connection, logger + schema: { ...campaigns }, connection, logger }); } diff --git a/src/app/components/top-up-form/top-up-form.component.html b/src/app/components/top-up-form/top-up-form.component.html index b166489..2e3a79a 100644 --- a/src/app/components/top-up-form/top-up-form.component.html +++ b/src/app/components/top-up-form/top-up-form.component.html @@ -42,7 +42,8 @@ This field is required } @else if(form.controls.amount.hasError('min')) { - Value must be at least {{ form.controls.amount.getError('min').min | currency:form.value.currency:'symbol-narrow' + Value must be at least {{ form.controls.amount.getError('min').min | + currency:form.value.currency:'symbol-narrow' }} } @@ -56,7 +57,7 @@
- +
diff --git a/src/app/components/top-up-form/top-up-form.component.ts b/src/app/components/top-up-form/top-up-form.component.ts index c238a5c..c114331 100644 --- a/src/app/components/top-up-form/top-up-form.component.ts +++ b/src/app/components/top-up-form/top-up-form.component.ts @@ -13,7 +13,7 @@ import { Fluid } from 'primeng/fluid'; import { InputNumber } from 'primeng/inputnumber'; import { Message } from 'primeng/message'; import { Select } from 'primeng/select'; -import { concatMap, distinctUntilKeyChanged, EMPTY } from 'rxjs'; +import { concatMap, distinctUntilKeyChanged, EMPTY, tap } from 'rxjs'; @Component({ selector: 'tm-top-up-form', @@ -135,14 +135,14 @@ export class TopUpFormComponent { dest: 'XAF' } }) - }) + }), ).subscribe({ next: ({ XAF }) => { this.exchangeRate.set(XAF); }, error: (error: HttpErrorResponse) => { this.error.emit(error.error ?? error); - }, + } }) } }