Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Migration file (#303)
Browse files Browse the repository at this point in the history
* migration file

* update

* alter tables

* Mix format

* Run only on postgres for now

---------

Co-authored-by: Javier Chatruc <[email protected]>
  • Loading branch information
igamigo and jrchatruc authored Sep 29, 2023
1 parent b201633 commit ed842af
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions priv/repo/migrations/20230929141348_change_blocks_pk.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
defmodule StarknetExplorer.Repo.Migrations.ChangeBlocksPk do
use Ecto.Migration

def change do
if System.get_env("DB_TYPE") == "postgresql" do
execute("alter table transactions drop constraint block_number;")
execute("alter table blocks drop constraint blocks_pkey;")
execute("alter table blocks add primary key (number, network);")

execute(
"alter table transactions add constraint transactions_blocks_fk foreign key (block_number, network) references blocks (number, network);"
)

execute(
"alter table events add constraint events_blocks_fk foreign key (block_number, network) references blocks (number, network);"
)
end
end
end

0 comments on commit ed842af

Please sign in to comment.