db: connection helper and invoices migration

DB.connect! opens a single Sequel connection from DATABASE_URL; DB.migrate!
runs Sequel migrations from db/migrations/.

The first migration creates the invoices table: uuid PK, unique invoice
number, client + currency fields, JSONB for line items, GEL conversion rate
captured at issue time, paid_at for the status toggle, pdf_key for the
MinIO object.
This commit is contained in:
Sergei Poljanski 2026-05-26 17:43:18 +03:00
commit 3fdb0f36b3
Signed by: asxpi
GPG key ID: 4F8851660FA4121B
2 changed files with 45 additions and 0 deletions

View file

@ -0,0 +1,23 @@
Sequel.migration do
change do
create_table(:invoices) do
column :uuid, :uuid, primary_key: true
String :number, null: false, unique: true
String :client_name, null: false
String :client_email, null: false
String :client_address, text: true
String :currency, null: false, size: 3
BigDecimal :gel_rate, size: [12, 4], null: false
BigDecimal :subtotal, size: [14, 2], null: false
column :items, :jsonb, null: false
Date :issued_on, null: false
Date :due_on, null: false
DateTime :paid_at
String :pdf_key, null: false
String :notes, text: true
DateTime :created_at, null: false
end
run "CREATE INDEX invoices_created_at_idx ON invoices (created_at DESC)"
end
end