File tree Expand file tree Collapse file tree
ex_cubic_ingestion/priv/repo/migrations Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ defmodule ExCubicIngestion.Repo.Migrations.AddingTables20260302 do
2+ use Ecto.Migration
3+
4+ alias ExCubicIngestion.Repo
5+ alias ExCubicIngestion.Schema.CubicTable
6+ alias ExCubicIngestion.Schema.CubicOdsTableSnapshot
7+
8+ @ ods_tables [
9+ % {
10+ name: "cubic_ods_qlik__edw_unsettled_crdb_sys_conf" ,
11+ s3_prefix: "cubic/ods_qlik/EDW.UNSETTLED_CRDB_SYS_CONF/"
12+ } ,
13+ ]
14+
15+ def up do
16+ Repo . transaction ( fn ->
17+ Enum . each ( @ ods_tables , fn ods_table ->
18+ ods_table_rec =
19+ Repo . insert! ( % CubicTable {
20+ name: ods_table [ :name ] ,
21+ s3_prefix: ods_table [ :s3_prefix ] ,
22+ is_active: true ,
23+ is_raw: true
24+ } )
25+
26+ Repo . insert! ( % CubicOdsTableSnapshot {
27+ table_id: ods_table_rec . id ,
28+ snapshot_s3_key: "#{ ods_table [ :s3_prefix ] } LOAD00000001.csv.gz"
29+ } )
30+ end )
31+ end )
32+ end
33+
34+ def down do
35+ Repo . transaction ( fn ->
36+ Enum . each ( @ ods_tables , fn ods_table ->
37+ ods_table_rec = CubicTable . get_by! ( name: ods_table [ :name ] )
38+ Repo . delete! ( ods_table_rec )
39+ Repo . delete! ( CubicOdsTableSnapshot . get_by! ( table_id: ods_table_rec . id ) )
40+ end )
41+ end )
42+ end
43+ end
You can’t perform that action at this time.
0 commit comments