|
28 | 28 | UUID_1_EPOCH = datetime(1582, 10, 15, tzinfo=timezone.utc)
|
29 | 29 | UUID_TICKS = 10000000
|
30 | 30 | UUID_VARIANT_1 = 0b1000000000000000
|
31 |
| -ROWS_TO_COMMIT_AT_ONCE = 10000 |
32 |
| -MONTHS_TO_KEEP = 1 |
| 31 | +ROWS_TO_COMMIT_AT_ONCE = 1000 |
| 32 | +MONTHS_TO_KEEP = 0.1 |
33 | 33 | # To avoid foreign key constraints, just shift the range of artifacts to keep a bit
|
34 | 34 | ARTIFACT_MONTHS_TO_KEEP = 0.75 * MONTHS_TO_KEEP
|
35 | 35 | MIGRATION_LIMIT = 10000000000 # mostly for testing purposes
|
|
69 | 69 |
|
70 | 70 | # json indexes for the tables
|
71 | 71 | INDEXES = {
|
72 |
| - # "results": [ |
73 |
| - # ], |
74 |
| - # "runs": [ |
75 |
| - # ], |
| 72 | + "results": [ |
| 73 | + "CREATE INDEX ix_results_jenkins_job_name ON results((data->'jenkins'->>'job_name'));", |
| 74 | + "CREATE INDEX ix_results_jenkins_build_number " |
| 75 | + "ON results((data->'jenkins'->>'build_number'));", |
| 76 | + "CREATE INDEX ix_results_classification ON results((data->>'classification'));", |
| 77 | + "CREATE INDEX ix_results_assignee ON results((data->>'assignee'));", |
| 78 | + "CREATE INDEX ix_results_exception_name ON results((data->>'exception_name'));", |
| 79 | + ], |
| 80 | + "runs": [ |
| 81 | + "CREATE INDEX ix_runs_jenkins_job_name ON runs((data->'jenkins'->>'job_name'));" |
| 82 | + "CREATE INDEX ix_runs_jenkins_build_number ON runs((data->'jenkins'->>'build_number'));" |
| 83 | + ], |
76 | 84 | }
|
77 | 85 |
|
78 | 86 |
|
@@ -127,10 +135,6 @@ def setup_postgres(postgres_url):
|
127 | 135 | def migrate_table(collection, Model, vprint, filter_=None):
|
128 | 136 | """Migrate a collection from MongoDB into a table in PostgreSQL"""
|
129 | 137 | # TODO: update indexes once we know them
|
130 |
| - conn = Base.metadata.bind.connect() |
131 |
| - for sql_index in INDEXES.get(Model.__tablename__, []): |
132 |
| - vprint(".", end="") |
133 |
| - conn.execute(sql_index) |
134 | 138 |
|
135 | 139 | if Model.__tablename__ == "runs":
|
136 | 140 | run_ids = []
|
@@ -195,6 +199,8 @@ def migrate_table(collection, Model, vprint, filter_=None):
|
195 | 199 | if row.get("params") and row["params"].get("sort_field"):
|
196 | 200 | # we no longer use this field
|
197 | 201 | row["params"].pop("sort_field")
|
| 202 | + if row.get("params") and row["params"].get("group_field") == "metadata.component": |
| 203 | + row["params"]["group_field"] = "component" |
198 | 204 |
|
199 | 205 | obj = Model.from_dict(**row)
|
200 | 206 | session.add(obj)
|
@@ -288,6 +294,13 @@ def migrate_tables(mongo, vprint, migrate_files=False):
|
288 | 294 |
|
289 | 295 | # loop over collections and migrate
|
290 | 296 | for collection, model in TABLE_MAP:
|
| 297 | + # first create indexes for the table |
| 298 | + conn = Base.metadata.bind.connect() |
| 299 | + for sql_index in INDEXES.get(model.__tablename__, []): |
| 300 | + vprint(".", end="") |
| 301 | + conn.execute(sql_index) |
| 302 | + |
| 303 | + # migrate the table over |
291 | 304 | vprint("Migrating {} ".format(collection), end="")
|
292 | 305 | if collection == "runs":
|
293 | 306 | run_ids = migrate_table(mongo[collection], model, vprint, filter_=filter_)
|
|
0 commit comments