diff --git a/migrations/schemas/20240524142655-add-soft-delete-vaults-table.sql b/migrations/schemas/20240524142655-add-soft-delete-vaults-table.sql new file mode 100644 index 00000000..b1d6c050 --- /dev/null +++ b/migrations/schemas/20240524142655-add-soft-delete-vaults-table.sql @@ -0,0 +1,9 @@ +-- +migrate Up +ALTER TABLE + vaults +ADD + COLUMN deleted_at timestamptz; + +-- +migrate Down +ALTER TABLE + vaults DROP COLUMN deleted_at; \ No newline at end of file diff --git a/pkg/model/vault.go b/pkg/model/vault.go index 67c52730..c3eb9e21 100644 --- a/pkg/model/vault.go +++ b/pkg/model/vault.go @@ -12,6 +12,7 @@ type Vault struct { WalletNumber int64 `json:"wallet_number"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` + DeletedAt *time.Time `json:"deleted_at"` VaultTreasurers []VaultTreasurer `json:"vault_treasurers" gorm:"foreignkey:VaultId"` TotalAmountEVM string `json:"total_amount_evm" gorm:"-"` TotalAmountSolana string `json:"total_amount_solana" gorm:"-"` diff --git a/pkg/repo/vault/pg.go b/pkg/repo/vault/pg.go index 2ba17efa..8a5a0c04 100644 --- a/pkg/repo/vault/pg.go +++ b/pkg/repo/vault/pg.go @@ -44,6 +44,9 @@ func (pg *pg) GetLatestWalletNumber() (walletNumber sql.NullInt64, err error) { func (pg *pg) List(q ListQuery) (vaults []model.Vault, err error) { db := pg.db + if !q.GetArchived { + db = db.Where("vaults.deleted_at IS NULL") + } if q.GuildID != "" { db = db.Where("vaults.guild_id = ?", q.GuildID) } diff --git a/pkg/repo/vault/query.go b/pkg/repo/vault/query.go index e57d95ec..a22d8319 100644 --- a/pkg/repo/vault/query.go +++ b/pkg/repo/vault/query.go @@ -7,4 +7,5 @@ type ListQuery struct { SolanaWallet string Threshold string VaultIDs []string + GetArchived bool }