Skip to content

Commit e1e0920

Browse files
authored
Add created_at indexes and on compiled_contracts_sources also the column (#36)
1 parent f1c0cfe commit e1e0920

2 files changed

Lines changed: 105 additions & 2 deletions

File tree

database.sql

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,8 @@ CREATE TABLE public.compiled_contracts_sources (
907907
id uuid DEFAULT gen_random_uuid() NOT NULL,
908908
compilation_id uuid NOT NULL,
909909
source_hash bytea NOT NULL,
910-
path character varying NOT NULL
910+
path character varying NOT NULL,
911+
created_at timestamp with time zone DEFAULT now() NOT NULL
911912
);
912913

913914

@@ -1138,6 +1139,20 @@ ALTER TABLE ONLY public.verified_contracts
11381139
CREATE INDEX code_code_hash_keccak ON public.code USING btree (code_hash_keccak);
11391140

11401141

1142+
--
1143+
-- Name: code_created_at; Type: INDEX; Schema: public; Owner: -
1144+
--
1145+
1146+
CREATE INDEX code_created_at ON public.code USING btree (created_at);
1147+
1148+
1149+
--
1150+
-- Name: compiled_contracts_created_at; Type: INDEX; Schema: public; Owner: -
1151+
--
1152+
1153+
CREATE INDEX compiled_contracts_created_at ON public.compiled_contracts USING btree (created_at);
1154+
1155+
11411156
--
11421157
-- Name: compiled_contracts_creation_code_hash; Type: INDEX; Schema: public; Owner: -
11431158
--
@@ -1159,6 +1174,13 @@ CREATE INDEX compiled_contracts_runtime_code_hash ON public.compiled_contracts U
11591174
CREATE INDEX compiled_contracts_sources_compilation_id ON public.compiled_contracts_sources USING btree (compilation_id);
11601175

11611176

1177+
--
1178+
-- Name: compiled_contracts_sources_created_at; Type: INDEX; Schema: public; Owner: -
1179+
--
1180+
1181+
CREATE INDEX compiled_contracts_sources_created_at ON public.compiled_contracts_sources USING btree (created_at);
1182+
1183+
11621184
--
11631185
-- Name: compiled_contracts_sources_source_hash; Type: INDEX; Schema: public; Owner: -
11641186
--
@@ -1180,6 +1202,20 @@ CREATE INDEX contract_deployments_address ON public.contract_deployments USING b
11801202
CREATE INDEX contract_deployments_contract_id ON public.contract_deployments USING btree (contract_id);
11811203

11821204

1205+
--
1206+
-- Name: contract_deployments_created_at; Type: INDEX; Schema: public; Owner: -
1207+
--
1208+
1209+
CREATE INDEX contract_deployments_created_at ON public.contract_deployments USING btree (created_at);
1210+
1211+
1212+
--
1213+
-- Name: contracts_created_at; Type: INDEX; Schema: public; Owner: -
1214+
--
1215+
1216+
CREATE INDEX contracts_created_at ON public.contracts USING btree (created_at);
1217+
1218+
11831219
--
11841220
-- Name: contracts_creation_code_hash; Type: INDEX; Schema: public; Owner: -
11851221
--
@@ -1201,13 +1237,27 @@ CREATE INDEX contracts_creation_code_hash_runtime_code_hash ON public.contracts
12011237
CREATE INDEX contracts_runtime_code_hash ON public.contracts USING btree (runtime_code_hash);
12021238

12031239

1240+
--
1241+
-- Name: sources_created_at; Type: INDEX; Schema: public; Owner: -
1242+
--
1243+
1244+
CREATE INDEX sources_created_at ON public.sources USING btree (created_at);
1245+
1246+
12041247
--
12051248
-- Name: verified_contracts_compilation_id; Type: INDEX; Schema: public; Owner: -
12061249
--
12071250

12081251
CREATE INDEX verified_contracts_compilation_id ON public.verified_contracts USING btree (compilation_id);
12091252

12101253

1254+
--
1255+
-- Name: verified_contracts_created_at; Type: INDEX; Schema: public; Owner: -
1256+
--
1257+
1258+
CREATE INDEX verified_contracts_created_at ON public.verified_contracts USING btree (created_at);
1259+
1260+
12111261
--
12121262
-- Name: verified_contracts_deployment_id; Type: INDEX; Schema: public; Owner: -
12131263
--
@@ -1229,6 +1279,13 @@ CREATE TRIGGER insert_set_created_at BEFORE INSERT ON public.code FOR EACH ROW E
12291279
CREATE TRIGGER insert_set_created_at BEFORE INSERT ON public.compiled_contracts FOR EACH ROW EXECUTE FUNCTION public.trigger_set_created_at();
12301280

12311281

1282+
--
1283+
-- Name: compiled_contracts_sources insert_set_created_at; Type: TRIGGER; Schema: public; Owner: -
1284+
--
1285+
1286+
CREATE TRIGGER insert_set_created_at BEFORE INSERT ON public.compiled_contracts_sources FOR EACH ROW EXECUTE FUNCTION public.trigger_set_created_at();
1287+
1288+
12321289
--
12331290
-- Name: contract_deployments insert_set_created_at; Type: TRIGGER; Schema: public; Owner: -
12341291
--
@@ -1397,6 +1454,13 @@ CREATE TRIGGER update_reuse_created_at BEFORE UPDATE ON public.code FOR EACH ROW
13971454
CREATE TRIGGER update_reuse_created_at BEFORE UPDATE ON public.compiled_contracts FOR EACH ROW EXECUTE FUNCTION public.trigger_reuse_created_at();
13981455

13991456

1457+
--
1458+
-- Name: compiled_contracts_sources update_reuse_created_at; Type: TRIGGER; Schema: public; Owner: -
1459+
--
1460+
1461+
CREATE TRIGGER update_reuse_created_at BEFORE UPDATE ON public.compiled_contracts_sources FOR EACH ROW EXECUTE FUNCTION public.trigger_reuse_created_at();
1462+
1463+
14001464
--
14011465
-- Name: contract_deployments update_reuse_created_at; Type: TRIGGER; Schema: public; Owner: -
14021466
--
@@ -1635,4 +1699,5 @@ ALTER TABLE ONLY public.verified_contracts
16351699
INSERT INTO public.schema_migrations (version) VALUES
16361700
('20250717103432'),
16371701
('20250723145429'),
1638-
('20251023134207');
1702+
('20251023134207'),
1703+
('20251106144315');
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
-- migrate:up
2+
3+
ALTER TABLE compiled_contracts_sources
4+
ADD COLUMN created_at timestamptz NOT NULL DEFAULT NOW();
5+
6+
CREATE TRIGGER insert_set_created_at
7+
BEFORE INSERT ON compiled_contracts_sources
8+
FOR EACH ROW
9+
EXECUTE FUNCTION trigger_set_created_at();
10+
11+
CREATE TRIGGER update_reuse_created_at
12+
BEFORE UPDATE ON compiled_contracts_sources
13+
FOR EACH ROW
14+
EXECUTE FUNCTION trigger_reuse_created_at();
15+
16+
CREATE INDEX code_created_at ON code USING btree(created_at);
17+
CREATE INDEX compiled_contracts_created_at ON compiled_contracts USING btree(created_at);
18+
CREATE INDEX compiled_contracts_sources_created_at ON compiled_contracts_sources USING btree(created_at);
19+
CREATE INDEX contract_deployments_created_at ON contract_deployments USING btree(created_at);
20+
CREATE INDEX contracts_created_at ON contracts USING btree(created_at);
21+
CREATE INDEX sources_created_at ON sources USING btree(created_at);
22+
CREATE INDEX verified_contracts_created_at ON verified_contracts USING btree(created_at);
23+
24+
-- migrate:down
25+
26+
DROP INDEX IF EXISTS verified_contracts_created_at;
27+
DROP INDEX IF EXISTS sources_created_at;
28+
DROP INDEX IF EXISTS contracts_created_at;
29+
DROP INDEX IF EXISTS contract_deployments_created_at;
30+
DROP INDEX IF EXISTS compiled_contracts_sources_created_at;
31+
DROP INDEX IF EXISTS compiled_contracts_created_at;
32+
DROP INDEX IF EXISTS code_created_at;
33+
34+
DROP TRIGGER IF EXISTS update_reuse_created_at ON compiled_contracts_sources;
35+
DROP TRIGGER IF EXISTS insert_set_created_at ON compiled_contracts_sources;
36+
37+
ALTER TABLE compiled_contracts_sources
38+
DROP COLUMN IF EXISTS created_at;

0 commit comments

Comments
 (0)