This repository was archived by the owner on Feb 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
🗃️ DB schema changes #162
Open
garry-sharp
wants to merge
1
commit into
fee-code-location-move
Choose a base branch
from
fees-v3-db
base: fee-code-location-move
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
🗃️ DB schema changes #162
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,42 +1,19 @@ | ||||||||||
| -- +goose Up | ||||||||||
| -- +goose StatementBegin | ||||||||||
| -- Create fee_run table | ||||||||||
| CREATE TABLE IF NOT EXISTS fee_run ( | ||||||||||
| id UUID PRIMARY KEY DEFAULT gen_random_uuid(), | ||||||||||
| status VARCHAR(50) NOT NULL DEFAULT 'draft' CHECK (status IN ('draft', 'sent', 'completed', 'failed')), | ||||||||||
| created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), | ||||||||||
| updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), | ||||||||||
| tx_hash VARCHAR(66), | ||||||||||
| policy_id UUID NOT NULL REFERENCES plugin_policies(id) ON DELETE CASCADE | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| -- Create fee table | ||||||||||
| CREATE TABLE IF NOT EXISTS fee ( | ||||||||||
| id UUID PRIMARY KEY, | ||||||||||
| fee_run_id UUID NOT NULL REFERENCES fee_run(id) ON DELETE CASCADE, | ||||||||||
| amount INTEGER NOT NULL, | ||||||||||
| created_at TIMESTAMP DEFAULT NOW() | ||||||||||
| ); | ||||||||||
| CREATE TYPE fee_batch_status as ENUM ('draft', 'sent', 'completed', 'failed'); | ||||||||||
|
|
||||||||||
| -- Create view for fee runs with total amounts | ||||||||||
| CREATE OR REPLACE VIEW fee_run_with_totals AS | ||||||||||
| SELECT | ||||||||||
| fr.id, | ||||||||||
| fr.status, | ||||||||||
| fr.created_at, | ||||||||||
| fr.updated_at, | ||||||||||
| fr.tx_hash, | ||||||||||
| fr.policy_id, | ||||||||||
| COALESCE(SUM(fi.amount), 0) as total_amount, | ||||||||||
| COUNT(fi.id) as fee_count | ||||||||||
| FROM fee_run fr | ||||||||||
| LEFT JOIN fee fi ON fr.id = fi.fee_run_id | ||||||||||
| GROUP BY fr.id, fr.status, fr.created_at, fr.updated_at, fr.tx_hash, fr.policy_id; | ||||||||||
|
|
||||||||||
| -- Create indexes for better performance | ||||||||||
| CREATE INDEX IF NOT EXISTS idx_fee_run_status ON fee_run(status); | ||||||||||
| CREATE INDEX IF NOT EXISTS idx_fee_run_created_at ON fee_run(created_at); | ||||||||||
| CREATE INDEX IF NOT EXISTS idx_fee_id_fee_run_id ON fee(fee_run_id); | ||||||||||
| CREATE TABLE IF NOT EXISTS fee_batch ( | ||||||||||
| id UUID PRIMARY KEY DEFAULT gen_random_uuid(), | ||||||||||
| batch_id UUID NOT NULL, -- this is the id of the batch credit "fee" on the verifier | ||||||||||
| public_key VARCHAR(66) NOT NULL, | ||||||||||
| status fee_batch_status NOT NULL DEFAULT 'draft', | ||||||||||
| amount BIGINT NOT NULL, | ||||||||||
| created_at TIMESTAMP DEFAULT NOW(), | ||||||||||
| updated_at TIMESTAMP DEFAULT NOW(), | ||||||||||
|
Comment on lines
+13
to
+14
|
||||||||||
| created_at TIMESTAMP DEFAULT NOW(), | |
| updated_at TIMESTAMP DEFAULT NOW(), | |
| created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), | |
| updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), |
Copilot
AI
Aug 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The migration drops the update_updated_at_column() function in the Down section, but this function may be used by other tables or triggers in the database. Dropping it could break other functionality that depends on this shared function.
Suggested change
| DROP FUNCTION IF EXISTS update_updated_at_column(); |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The timestamp columns use different data types than the schema.sql file. Here
created_atusesTIMESTAMPwhile in schema.sql it usestimestamp with time zone. This inconsistency could lead to timezone-related issues.