|
| 1 | +CREATE TABLE IF NOT EXISTS "indexer_cursor" ( |
| 2 | + "id" integer PRIMARY KEY NOT NULL, |
| 3 | + "last_ledger" integer NOT NULL, |
| 4 | + "updated_at" timestamp with time zone DEFAULT now() NOT NULL |
| 5 | +); |
| 6 | +--> statement-breakpoint |
| 7 | +CREATE TABLE IF NOT EXISTS "markets" ( |
| 8 | + "id" text PRIMARY KEY NOT NULL, |
| 9 | + "question" text NOT NULL, |
| 10 | + "status" text NOT NULL, |
| 11 | + "resolution_time" timestamp with time zone NOT NULL, |
| 12 | + "metadata" jsonb, |
| 13 | + "indexed_ledger" integer NOT NULL, |
| 14 | + "archived" boolean DEFAULT false NOT NULL |
| 15 | +); |
| 16 | +--> statement-breakpoint |
| 17 | +CREATE TABLE IF NOT EXISTS "predictions" ( |
| 18 | + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, |
| 19 | + "market_id" text NOT NULL, |
| 20 | + "user_id" uuid NOT NULL, |
| 21 | + "outcome" text NOT NULL, |
| 22 | + "amount" text NOT NULL, |
| 23 | + "created_at" timestamp with time zone DEFAULT now() NOT NULL |
| 24 | +); |
| 25 | +--> statement-breakpoint |
| 26 | +CREATE TABLE IF NOT EXISTS "users" ( |
| 27 | + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, |
| 28 | + "stellar_address" text NOT NULL, |
| 29 | + "created_at" timestamp with time zone DEFAULT now() NOT NULL, |
| 30 | + CONSTRAINT "users_stellar_address_unique" UNIQUE("stellar_address") |
| 31 | +); |
| 32 | +--> statement-breakpoint |
| 33 | +DO $$ BEGIN |
| 34 | + 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; |
| 35 | +EXCEPTION |
| 36 | + WHEN duplicate_object THEN null; |
| 37 | +END $$; |
| 38 | +--> statement-breakpoint |
| 39 | +DO $$ BEGIN |
| 40 | + 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; |
| 41 | +EXCEPTION |
| 42 | + WHEN duplicate_object THEN null; |
| 43 | +END $$; |
0 commit comments