-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
pkg/postgres/migrations/202411191708_operatorPISplits/up.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package _202411191708_operatorPISplits | ||
|
||
import ( | ||
"database/sql" | ||
|
||
"gorm.io/gorm" | ||
) | ||
|
||
type Migration struct { | ||
} | ||
|
||
func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error { | ||
query := ` | ||
create table if not exists operator_pi_splits ( | ||
operator varchar not null, | ||
activated_at timestamp(6) not null, | ||
old_operator_avs_split_bips integer not null, | ||
new_operator_avs_split_bips integer not null, | ||
block_number bigint not null, | ||
transaction_hash varchar not null, | ||
log_index bigint not null, | ||
unique(transaction_hash, log_index, block_number) | ||
); | ||
` | ||
if err := grm.Exec(query).Error; err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (m *Migration) GetName() string { | ||
return "202411191708_operatorPISplits" | ||
} |
32 changes: 32 additions & 0 deletions
32
pkg/postgres/migrations/202411191710_blockNumberFkConstraint/up.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package _202411191710_blockNumberFkConstraint | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
|
||
"gorm.io/gorm" | ||
) | ||
|
||
type Migration struct { | ||
} | ||
|
||
func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error { | ||
queries := []string{ | ||
`alter table operator_directed_reward_submissions add constraint operator_directed_reward_submissions_block_number_fkey foreign key (block_number) references blocks (number) on delete cascade`, | ||
`alter table operator_avs_splits add constraint operator_avs_splits_block_number_fkey foreign key (block_number) references blocks (number) on delete cascade`, | ||
`alter table operator_pi_splits add constraint operator_pi_splits_block_number_fkey foreign key (block_number) references blocks (number) on delete cascade`, | ||
} | ||
|
||
for _, query := range queries { | ||
_, err := db.Exec(query) | ||
if err != nil { | ||
fmt.Printf("Failed to run migration query: %s - %+v\n", query, err) | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (m *Migration) GetName() string { | ||
return "202411191710_blockNumberFkConstraint" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters