|
| 1 | + |
| 2 | +CREATE TYPE "plugin_id" AS ENUM ( |
| 3 | + 'vultisig-dca-0000', |
| 4 | + 'vultisig-payroll-0000', |
| 5 | + 'vultisig-fees-feee' |
| 6 | +); |
| 7 | + |
| 8 | +CREATE TYPE "transaction_status" AS ENUM ( |
| 9 | + 'PENDING', |
| 10 | + 'SIGNING_FAILED', |
| 11 | + 'SIGNED', |
| 12 | + 'BROADCAST', |
| 13 | + 'MINED', |
| 14 | + 'REJECTED' |
| 15 | +); |
| 16 | + |
| 17 | +CREATE TYPE "trigger_status" AS ENUM ( |
| 18 | + 'PENDING', |
| 19 | + 'RUNNING' |
| 20 | +); |
| 21 | + |
| 22 | +CREATE TYPE "tx_indexer_status" AS ENUM ( |
| 23 | + 'PROPOSED', |
| 24 | + 'VERIFIED', |
| 25 | + 'SIGNED' |
| 26 | +); |
| 27 | + |
| 28 | +CREATE TYPE "tx_indexer_status_onchain" AS ENUM ( |
| 29 | + 'PENDING', |
| 30 | + 'SUCCESS', |
| 31 | + 'FAIL' |
| 32 | +); |
| 33 | + |
| 34 | +CREATE TABLE "plugin_policies" ( |
| 35 | + "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL, |
| 36 | + "public_key" "text" NOT NULL, |
| 37 | + "plugin_id" "plugin_id" NOT NULL, |
| 38 | + "plugin_version" "text" NOT NULL, |
| 39 | + "policy_version" integer NOT NULL, |
| 40 | + "signature" "text" NOT NULL, |
| 41 | + "recipe" "text" NOT NULL, |
| 42 | + "active" boolean DEFAULT true NOT NULL, |
| 43 | + "created_at" timestamp with time zone DEFAULT "now"() NOT NULL, |
| 44 | + "updated_at" timestamp with time zone DEFAULT "now"() NOT NULL |
| 45 | +); |
| 46 | + |
| 47 | +CREATE TABLE "time_triggers" ( |
| 48 | + "id" integer NOT NULL, |
| 49 | + "policy_id" "uuid" NOT NULL, |
| 50 | + "cron_expression" "text" NOT NULL, |
| 51 | + "start_time" timestamp without time zone NOT NULL, |
| 52 | + "end_time" timestamp without time zone, |
| 53 | + "frequency" integer NOT NULL, |
| 54 | + "interval" integer NOT NULL, |
| 55 | + "last_execution" timestamp without time zone, |
| 56 | + "status" "trigger_status" NOT NULL, |
| 57 | + "created_at" timestamp without time zone DEFAULT CURRENT_TIMESTAMP |
| 58 | +); |
| 59 | + |
| 60 | +CREATE SEQUENCE "time_triggers_id_seq" |
| 61 | + AS integer |
| 62 | + START WITH 1 |
| 63 | + INCREMENT BY 1 |
| 64 | + NO MINVALUE |
| 65 | + NO MAXVALUE |
| 66 | + CACHE 1; |
| 67 | + |
| 68 | +ALTER SEQUENCE "time_triggers_id_seq" OWNED BY "public"."time_triggers"."id"; |
| 69 | + |
| 70 | +CREATE TABLE "transaction_history" ( |
| 71 | + "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL, |
| 72 | + "policy_id" "uuid" NOT NULL, |
| 73 | + "tx_body" "text" NOT NULL, |
| 74 | + "tx_hash" "text" NOT NULL, |
| 75 | + "status" "transaction_status" NOT NULL, |
| 76 | + "created_at" timestamp with time zone DEFAULT "now"(), |
| 77 | + "updated_at" timestamp with time zone DEFAULT "now"(), |
| 78 | + "metadata" "jsonb", |
| 79 | + "error_message" "text" |
| 80 | +); |
| 81 | + |
| 82 | +CREATE TABLE "tx_indexer" ( |
| 83 | + "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL, |
| 84 | + "plugin_id" character varying(255) NOT NULL, |
| 85 | + "tx_hash" character varying(255), |
| 86 | + "chain_id" integer NOT NULL, |
| 87 | + "policy_id" "uuid" NOT NULL, |
| 88 | + "from_public_key" character varying(255) NOT NULL, |
| 89 | + "proposed_tx_hex" "text" NOT NULL, |
| 90 | + "status" "tx_indexer_status" DEFAULT 'PROPOSED'::"public"."tx_indexer_status" NOT NULL, |
| 91 | + "status_onchain" "tx_indexer_status_onchain", |
| 92 | + "lost" boolean DEFAULT false NOT NULL, |
| 93 | + "broadcasted_at" timestamp without time zone, |
| 94 | + "created_at" timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, |
| 95 | + "updated_at" timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL |
| 96 | +); |
| 97 | + |
| 98 | +ALTER TABLE ONLY "time_triggers" ALTER COLUMN "id" SET DEFAULT "nextval"('"public"."time_triggers_id_seq"'::"regclass"); |
| 99 | + |
| 100 | +ALTER TABLE ONLY "plugin_policies" |
| 101 | + ADD CONSTRAINT "plugin_policies_pkey" PRIMARY KEY ("id"); |
| 102 | + |
| 103 | +ALTER TABLE ONLY "time_triggers" |
| 104 | + ADD CONSTRAINT "time_triggers_pkey" PRIMARY KEY ("id"); |
| 105 | + |
| 106 | +ALTER TABLE ONLY "transaction_history" |
| 107 | + ADD CONSTRAINT "transaction_history_pkey" PRIMARY KEY ("id"); |
| 108 | + |
| 109 | +ALTER TABLE ONLY "tx_indexer" |
| 110 | + ADD CONSTRAINT "tx_indexer_pkey" PRIMARY KEY ("id"); |
| 111 | + |
| 112 | +ALTER TABLE ONLY "transaction_history" |
| 113 | + ADD CONSTRAINT "unique_tx_hash" UNIQUE ("tx_hash"); |
| 114 | + |
| 115 | +CREATE INDEX "idx_plugin_policies_active" ON "plugin_policies" USING "btree" ("active"); |
| 116 | + |
| 117 | +CREATE INDEX "idx_plugin_policies_plugin_id" ON "plugin_policies" USING "btree" ("plugin_id"); |
| 118 | + |
| 119 | +CREATE INDEX "idx_plugin_policies_public_key" ON "plugin_policies" USING "btree" ("public_key"); |
| 120 | + |
| 121 | +CREATE INDEX "idx_time_triggers_policy_id" ON "time_triggers" USING "btree" ("policy_id"); |
| 122 | + |
| 123 | +CREATE INDEX "idx_time_triggers_start_time" ON "time_triggers" USING "btree" ("start_time"); |
| 124 | + |
| 125 | +CREATE INDEX "idx_transaction_history_policy_id" ON "transaction_history" USING "btree" ("policy_id"); |
| 126 | + |
| 127 | +CREATE INDEX "idx_transaction_history_status" ON "transaction_history" USING "btree" ("status"); |
| 128 | + |
| 129 | +CREATE INDEX "idx_transaction_history_tx_hash" ON "transaction_history" USING "btree" ("tx_hash"); |
| 130 | + |
| 131 | +CREATE INDEX "idx_tx_indexer_status_onchain_lost" ON "tx_indexer" USING "btree" ("status_onchain", "lost"); |
| 132 | + |
| 133 | +ALTER TABLE ONLY "transaction_history" |
| 134 | + ADD CONSTRAINT "fk_policy" FOREIGN KEY ("policy_id") REFERENCES "plugin_policies"("id"); |
| 135 | + |
| 136 | +ALTER TABLE ONLY "time_triggers" |
| 137 | + ADD CONSTRAINT "time_triggers_policy_id_fkey" FOREIGN KEY ("policy_id") REFERENCES "plugin_policies"("id"); |
| 138 | + |
| 139 | +ALTER TABLE ONLY "transaction_history" |
| 140 | + ADD CONSTRAINT "transaction_history_policy_id_fkey" FOREIGN KEY ("policy_id") REFERENCES "plugin_policies"("id"); |
| 141 | + |
0 commit comments