feat: implement notification system

This commit is contained in:
Face 2025-06-11 18:37:03 +03:00
parent de3f8a4929
commit e61c41e414
19 changed files with 883 additions and 3196 deletions

View file

@ -1,3 +1,9 @@
DO $$ BEGIN
CREATE TYPE "public"."notification_type" AS ENUM('HOPIUM', 'SYSTEM', 'TRANSFER', 'RUG_PULL');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "public"."prediction_market_status" AS ENUM('ACTIVE', 'RESOLVED', 'CANCELLED');
EXCEPTION
@ -5,7 +11,7 @@ EXCEPTION
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "public"."transaction_type" AS ENUM('BUY', 'SELL');
CREATE TYPE "public"."transaction_type" AS ENUM('BUY', 'SELL', 'TRANSFER_IN', 'TRANSFER_OUT');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
@ -47,7 +53,7 @@ CREATE TABLE IF NOT EXISTS "coin" (
"current_price" numeric(20, 8) NOT NULL,
"market_cap" numeric(30, 2) NOT NULL,
"volume_24h" numeric(30, 2) DEFAULT '0.00',
"change_24h" numeric(10, 4) DEFAULT '0.0000',
"change_24h" numeric(30, 4) DEFAULT '0.0000',
"pool_coin_amount" numeric(30, 8) DEFAULT '0.00000000' NOT NULL,
"pool_base_currency_amount" numeric(30, 8) DEFAULT '0.00000000' NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
@ -74,6 +80,16 @@ CREATE TABLE IF NOT EXISTS "comment_like" (
CONSTRAINT "comment_like_user_id_comment_id_pk" PRIMARY KEY("user_id","comment_id")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "notification" (
"id" serial PRIMARY KEY NOT NULL,
"user_id" integer NOT NULL,
"type" "notification_type" NOT NULL,
"title" varchar(200) NOT NULL,
"message" text NOT NULL,
"is_read" boolean DEFAULT false NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "prediction_bet" (
"id" serial PRIMARY KEY NOT NULL,
"user_id" integer,
@ -149,7 +165,9 @@ CREATE TABLE IF NOT EXISTS "transaction" (
"quantity" numeric(30, 8) NOT NULL,
"price_per_coin" numeric(20, 8) NOT NULL,
"total_base_currency_amount" numeric(30, 8) NOT NULL,
"timestamp" timestamp with time zone DEFAULT now() NOT NULL
"timestamp" timestamp with time zone DEFAULT now() NOT NULL,
"recipient_user_id" integer,
"sender_user_id" integer
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "user" (
@ -234,6 +252,12 @@ EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "notification" ADD CONSTRAINT "notification_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "prediction_bet" ADD CONSTRAINT "prediction_bet_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
@ -294,6 +318,18 @@ EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "transaction" ADD CONSTRAINT "transaction_recipient_user_id_user_id_fk" FOREIGN KEY ("recipient_user_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "transaction" ADD CONSTRAINT "transaction_sender_user_id_user_id_fk" FOREIGN KEY ("sender_user_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "user_portfolio" ADD CONSTRAINT "user_portfolio_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
@ -311,6 +347,10 @@ CREATE INDEX IF NOT EXISTS "account_deletion_request_scheduled_deletion_idx" ON
CREATE INDEX IF NOT EXISTS "account_deletion_request_open_idx" ON "account_deletion_request" USING btree ("user_id") WHERE is_processed = false;--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "comment_user_id_idx" ON "comment" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "comment_coin_id_idx" ON "comment" USING btree ("coin_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "notification_user_id_idx" ON "notification" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "notification_type_idx" ON "notification" USING btree ("type");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "notification_is_read_idx" ON "notification" USING btree ("is_read");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "notification_created_at_idx" ON "notification" USING btree ("created_at");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "prediction_bet_user_id_idx" ON "prediction_bet" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "prediction_bet_question_id_idx" ON "prediction_bet" USING btree ("question_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "prediction_bet_user_question_idx" ON "prediction_bet" USING btree ("user_id","question_id");--> statement-breakpoint

View file

@ -1,15 +0,0 @@
ALTER TYPE "transaction_type" ADD VALUE 'TRANSFER_IN';--> statement-breakpoint
ALTER TYPE "transaction_type" ADD VALUE 'TRANSFER_OUT';--> statement-breakpoint
ALTER TABLE "transaction" ADD COLUMN "recipient_user_id" integer;--> statement-breakpoint
ALTER TABLE "transaction" ADD COLUMN "sender_user_id" integer;--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "transaction" ADD CONSTRAINT "transaction_recipient_user_id_user_id_fk" FOREIGN KEY ("recipient_user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "transaction" ADD CONSTRAINT "transaction_sender_user_id_user_id_fk" FOREIGN KEY ("sender_user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

View file

@ -1,16 +0,0 @@
ALTER TABLE "transaction" DROP CONSTRAINT "transaction_recipient_user_id_user_id_fk";
--> statement-breakpoint
ALTER TABLE "transaction" DROP CONSTRAINT "transaction_sender_user_id_user_id_fk";
--> statement-breakpoint
ALTER TABLE "coin" ALTER COLUMN "change_24h" SET DATA TYPE numeric(30, 4);--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "transaction" ADD CONSTRAINT "transaction_recipient_user_id_user_id_fk" FOREIGN KEY ("recipient_user_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "transaction" ADD CONSTRAINT "transaction_sender_user_id_user_id_fk" FOREIGN KEY ("sender_user_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

View file

@ -1,5 +1,5 @@
{
"id": "077132a0-ccad-4d56-855b-150b8fe31d94",
"id": "41f7bba3-1d5d-41ba-83bb-ca129ace81f0",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
@ -292,7 +292,7 @@
},
"change_24h": {
"name": "change_24h",
"type": "numeric(10, 4)",
"type": "numeric(30, 4)",
"primaryKey": false,
"notNull": false,
"default": "'0.0000'"
@ -544,6 +544,136 @@
},
"uniqueConstraints": {}
},
"public.notification": {
"name": "notification",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"type": {
"name": "type",
"type": "notification_type",
"typeSchema": "public",
"primaryKey": false,
"notNull": true
},
"title": {
"name": "title",
"type": "varchar(200)",
"primaryKey": false,
"notNull": true
},
"message": {
"name": "message",
"type": "text",
"primaryKey": false,
"notNull": true
},
"is_read": {
"name": "is_read",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"notification_user_id_idx": {
"name": "notification_user_id_idx",
"columns": [
{
"expression": "user_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"notification_type_idx": {
"name": "notification_type_idx",
"columns": [
{
"expression": "type",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"notification_is_read_idx": {
"name": "notification_is_read_idx",
"columns": [
{
"expression": "is_read",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"notification_created_at_idx": {
"name": "notification_created_at_idx",
"columns": [
{
"expression": "created_at",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"notification_user_id_user_id_fk": {
"name": "notification_user_id_user_id_fk",
"tableFrom": "notification",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.prediction_bet": {
"name": "prediction_bet",
"schema": "",
@ -1194,6 +1324,18 @@
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"recipient_user_id": {
"name": "recipient_user_id",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"sender_user_id": {
"name": "sender_user_id",
"type": "integer",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
@ -1223,6 +1365,32 @@
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"transaction_recipient_user_id_user_id_fk": {
"name": "transaction_recipient_user_id_user_id_fk",
"tableFrom": "transaction",
"tableTo": "user",
"columnsFrom": [
"recipient_user_id"
],
"columnsTo": [
"id"
],
"onDelete": "set null",
"onUpdate": "no action"
},
"transaction_sender_user_id_user_id_fk": {
"name": "transaction_sender_user_id_user_id_fk",
"tableFrom": "transaction",
"tableTo": "user",
"columnsFrom": [
"sender_user_id"
],
"columnsTo": [
"id"
],
"onDelete": "set null",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
@ -1492,6 +1660,16 @@
}
},
"enums": {
"public.notification_type": {
"name": "notification_type",
"schema": "public",
"values": [
"HOPIUM",
"SYSTEM",
"TRANSFER",
"RUG_PULL"
]
},
"public.prediction_market_status": {
"name": "prediction_market_status",
"schema": "public",
@ -1506,7 +1684,9 @@
"schema": "public",
"values": [
"BUY",
"SELL"
"SELL",
"TRANSFER_IN",
"TRANSFER_OUT"
]
}
},

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -5,22 +5,8 @@
{
"idx": 0,
"version": "7",
"when": 1748604150899,
"tag": "0000_spooky_umar",
"breakpoints": true
},
{
"idx": 1,
"version": "7",
"when": 1748690470287,
"tag": "0001_yummy_meggan",
"breakpoints": true
},
{
"idx": 2,
"version": "7",
"when": 1748700252762,
"tag": "0002_lush_guardian",
"when": 1749654046953,
"tag": "0000_crazy_bloodstrike",
"breakpoints": true
}
]