Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ jobs:

- run: npm run lint

- run: npm run test
- name: Run migrations
run: npm run db:migrate
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/predictify

- name: Check schema drift
run: npm run db:check-drift
- name: Run tests
run: npm run test
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/predictify

- name: Run migrations
run: npm run db:migrate
- name: Check schema drift
run: npm run db:check-drift
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/predictify
13 changes: 0 additions & 13 deletions drizzle/0000_contract_events.sql

This file was deleted.

47 changes: 0 additions & 47 deletions drizzle/0000_easy_black_bird.sql

This file was deleted.

46 changes: 0 additions & 46 deletions drizzle/0000_fantastic_vindicator.sql

This file was deleted.

233 changes: 233 additions & 0 deletions drizzle/0000_huge_red_shift.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
CREATE TABLE "admin_audit_log" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"admin_address" text NOT NULL,
"action" text NOT NULL,
"target_address" text NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "audit_logs" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"action" text NOT NULL,
"wallet_address" text,
"ip" text NOT NULL,
"correlation_id" text NOT NULL,
"rate_limit_context" jsonb,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "auth_challenges" (
"nonce" text PRIMARY KEY NOT NULL,
"stellar_address" text NOT NULL,
"expires_at" timestamp with time zone NOT NULL,
"used" boolean DEFAULT false NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "claims" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"user_id" uuid NOT NULL,
"market_id" text NOT NULL,
"amount" text NOT NULL,
"status" text DEFAULT 'pending' NOT NULL,
"settlement_tx" text,
"settle_attempts" integer DEFAULT 0 NOT NULL,
"next_settle_attempt_at" timestamp with time zone,
"settled_at" timestamp with time zone,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "contract_events" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"contract_id" text NOT NULL,
"ledger" integer NOT NULL,
"tx_hash" text NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "disputes" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"opened_by" uuid NOT NULL,
"market_id" text NOT NULL,
"reason" text NOT NULL,
"evidence_uri" text,
"status" text DEFAULT 'open' NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "feature_flags" (
"id" text PRIMARY KEY NOT NULL,
"enabled" boolean DEFAULT false NOT NULL,
"variant" text,
"description" text,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "fraud_flags" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"cluster_key" text NOT NULL,
"user_id" uuid NOT NULL,
"stellar_address" text NOT NULL,
"reason" text NOT NULL,
"evidence" jsonb DEFAULT '{}'::jsonb NOT NULL,
"score" integer DEFAULT 0 NOT NULL,
"status" text DEFAULT 'open' NOT NULL,
"reviewed_by" text,
"reviewed_at" timestamp with time zone,
"correlation_id" text,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "idempotency_records" (
"key" text PRIMARY KEY NOT NULL,
"fingerprint" text NOT NULL,
"response_status" integer NOT NULL,
"response_body" jsonb NOT NULL,
"response_headers" jsonb DEFAULT '{}'::jsonb NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"expires_at" timestamp with time zone NOT NULL
);
--> statement-breakpoint
CREATE TABLE "indexer_cursor" (
"id" integer PRIMARY KEY NOT NULL,
"last_ledger" integer NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "indexer_events" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"ledger" integer NOT NULL,
"tx_hash" text NOT NULL,
"op_index" integer DEFAULT 0 NOT NULL,
"event_type" text NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"market_id" text,
"data" jsonb
);
--> statement-breakpoint
CREATE TABLE "market_audit_log" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"market_id" text NOT NULL,
"admin_address" text NOT NULL,
"action" text NOT NULL,
"before_state" jsonb NOT NULL,
"after_state" jsonb NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "markets" (
"id" text PRIMARY KEY NOT NULL,
"question" text NOT NULL,
"status" text NOT NULL,
"resolution_outcome" text,
"resolution_time" timestamp with time zone NOT NULL,
"winning_outcome" text,
"metadata" jsonb,
"indexed_ledger" integer NOT NULL,
"archived" boolean DEFAULT false NOT NULL,
"version" integer DEFAULT 1 NOT NULL,
"featured" boolean DEFAULT false NOT NULL,
"featured_at" timestamp with time zone,
"featured_by" text,
"force_finalized" boolean DEFAULT false NOT NULL
);
--> statement-breakpoint
CREATE TABLE "notification_preferences" (
"user_id" uuid NOT NULL,
"category" text NOT NULL,
"channel" text NOT NULL,
"enabled" boolean DEFAULT true NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "notification_preferences_user_id_category_channel_pk" PRIMARY KEY("user_id","category","channel")
);
--> statement-breakpoint
CREATE TABLE "predictions" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"market_id" text NOT NULL,
"user_id" uuid NOT NULL,
"outcome" text NOT NULL,
"amount" text NOT NULL,
"tx_hash" text DEFAULT '' NOT NULL,
"funding_source" text,
"status" text DEFAULT 'pending' NOT NULL,
"result" text,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "refresh_tokens" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"user_id" uuid NOT NULL,
"token_hash" text NOT NULL,
"family_id" uuid NOT NULL,
"parent_id" uuid,
"expires_at" timestamp with time zone NOT NULL,
"revoked_at" timestamp with time zone,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "refresh_tokens_token_hash_unique" UNIQUE("token_hash")
);
--> statement-breakpoint
CREATE TABLE "users" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"stellar_address" text NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "users_stellar_address_unique" UNIQUE("stellar_address")
);
--> statement-breakpoint
CREATE TABLE "webhook_deliveries" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"subscription_id" uuid NOT NULL,
"event_type" text NOT NULL,
"payload" jsonb NOT NULL,
"status" text DEFAULT 'pending' NOT NULL,
"attempt" integer DEFAULT 0 NOT NULL,
"next_retry_at" timestamp with time zone DEFAULT now() NOT NULL,
"last_status_code" integer,
"last_error" text,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "webhook_deliveries_dlq" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"subscription_id" uuid NOT NULL,
"event_type" text NOT NULL,
"payload" jsonb NOT NULL,
"status" text DEFAULT 'dlq' NOT NULL,
"attempt" integer DEFAULT 0 NOT NULL,
"next_retry_at" timestamp with time zone DEFAULT now() NOT NULL,
"last_status_code" integer,
"last_error" text,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "webhook_subscriptions" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"url" text NOT NULL,
"secret" text NOT NULL,
"events" jsonb DEFAULT '[]'::jsonb NOT NULL,
"active" boolean DEFAULT true NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "claims" ADD CONSTRAINT "claims_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "claims" ADD CONSTRAINT "claims_market_id_markets_id_fk" FOREIGN KEY ("market_id") REFERENCES "public"."markets"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "disputes" ADD CONSTRAINT "disputes_opened_by_users_id_fk" FOREIGN KEY ("opened_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "disputes" ADD CONSTRAINT "disputes_market_id_markets_id_fk" FOREIGN KEY ("market_id") REFERENCES "public"."markets"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "fraud_flags" ADD CONSTRAINT "fraud_flags_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "market_audit_log" ADD CONSTRAINT "market_audit_log_market_id_markets_id_fk" FOREIGN KEY ("market_id") REFERENCES "public"."markets"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "notification_preferences" ADD CONSTRAINT "notification_preferences_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "predictions" ADD CONSTRAINT "predictions_market_id_markets_id_fk" FOREIGN KEY ("market_id") REFERENCES "public"."markets"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "predictions" ADD CONSTRAINT "predictions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "refresh_tokens" ADD CONSTRAINT "refresh_tokens_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "webhook_deliveries" ADD CONSTRAINT "webhook_deliveries_subscription_id_webhook_subscriptions_id_fk" FOREIGN KEY ("subscription_id") REFERENCES "public"."webhook_subscriptions"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "webhook_deliveries_dlq" ADD CONSTRAINT "webhook_deliveries_dlq_subscription_id_webhook_subscriptions_id_fk" FOREIGN KEY ("subscription_id") REFERENCES "public"."webhook_subscriptions"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "audit_logs_correlation_idx" ON "audit_logs" USING btree ("correlation_id");--> statement-breakpoint
CREATE INDEX "audit_logs_created_at_idx" ON "audit_logs" USING btree ("created_at");--> statement-breakpoint
CREATE INDEX "fraud_flags_status_created_idx" ON "fraud_flags" USING btree ("status","created_at");--> statement-breakpoint
CREATE INDEX "fraud_flags_address_idx" ON "fraud_flags" USING btree ("stellar_address");--> statement-breakpoint
CREATE INDEX "idempotency_expires_idx" ON "idempotency_records" USING btree ("expires_at");--> statement-breakpoint
CREATE INDEX "notification_preferences_user_id_idx" ON "notification_preferences" USING btree ("user_id");
23 changes: 0 additions & 23 deletions drizzle/0000_indexer_events.sql

This file was deleted.

Loading
Loading