-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
7eed35c
commit 3697169
Showing
9 changed files
with
83 additions
and
23 deletions.
There are no files selected for viewing
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
39 changes: 39 additions & 0 deletions
39
internal/storage/postgres/migrations/20241208_total_bytes.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,39 @@ | ||
// SPDX-FileCopyrightText: 2024 PK Lab AG <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
package migrations | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/celenium-io/astria-indexer/internal/storage" | ||
"github.com/uptrace/bun" | ||
) | ||
|
||
func init() { | ||
Migrations.MustRegister(upTotalBytes, downTotalBytes) | ||
} | ||
|
||
func upTotalBytes(ctx context.Context, db *bun.DB) error { | ||
_, err := db.ExecContext(ctx, `ALTER TABLE IF EXISTS public.state ADD COLUMN IF NOT EXISTS total_bytes int8 NULL`) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = db.ExecContext(ctx, `COMMENT ON COLUMN public.state.total_bytes IS 'Total rollup bytes'`) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var totalBytes int64 | ||
err = db.NewSelect().Model((*storage.Rollup)(nil)).ColumnExpr("sum(size)").Scan(ctx, &totalBytes) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = db.NewUpdate().Set("total_bytes = ?", totalBytes).Model((*storage.State)(nil)).Where("name = 'dipdup_astria_indexer'").Exec(ctx) | ||
return err | ||
} | ||
func downTotalBytes(ctx context.Context, db *bun.DB) error { | ||
_, err := db.ExecContext(ctx, `ALTER TABLE IF EXISTS public.state DROP COLUMN IF NOT EXISTS total_bytes`) | ||
return err | ||
} |
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,10 @@ | ||
// SPDX-FileCopyrightText: 2024 PK Lab AG <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
package migrations | ||
|
||
import ( | ||
"github.com/uptrace/bun/migrate" | ||
) | ||
|
||
var Migrations = migrate.NewMigrations() |
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
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
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
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
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
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