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

22
lib/db.rb Normal file
View file

@ -0,0 +1,22 @@
require 'sequel'
module DB
module_function
def connect!
@connection ||= Sequel.connect(
ENV.fetch('DATABASE_URL'),
max_connections: 5,
logger: ($env == 'development' ? $logger : nil)
)
end
def connection
@connection or raise 'DB not connected — call DB.connect! first'
end
def migrate!
Sequel.extension :migration
Sequel::Migrator.run(connection, File.join($root, 'db', 'migrations'))
end
end