Introduces separate databases and config files for dev, test, and prod environments. The application now defaults to production, with --env flag to specify alternative environments. Changes: - Update config.rs to support env-based loading (config.toml -> config.<env>.toml -> config.example.toml) - Add Env enum (Prod, Dev, Test) with database name mapping - Add --env flag to CLI commands (defaults to prod) - Add 'db setup' command to create database and schema - Split migrations into env-specific database creation and shared schema - Update .gitignore to track config.example.toml but ignore config.toml and config.<env>.toml files - Update config.example.toml as a template with placeholder values - Delete 001_initial_schema.sql, replaced by 002_schema.sql + env-specific files Config loading order: 1. config.toml (local override) 2. config.<env>.toml (environment-specific) 3. config.example.toml (fallback) Database names: - prod: rusty_petroleum - dev: rusty_petroleum_dev - test: rusty_petroleum_test Usage: cargo run -- db setup --env dev # Setup dev database cargo run -- import data.csv --env dev # Import to dev cargo run -- db setup # Setup prod (default) cargo run -- import data.csv # Import to prod (default)
50 lines
2.0 KiB
SQL
50 lines
2.0 KiB
SQL
-- Schema for rusty_petroleum
|
|
-- Run after creating the database
|
|
|
|
CREATE TABLE IF NOT EXISTS customers (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
customer_number VARCHAR(50) NOT NULL UNIQUE,
|
|
card_report_group TINYINT UNSIGNED NOT NULL DEFAULT 0,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
INDEX idx_customer_number (customer_number)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS cards (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
card_number VARCHAR(50) NOT NULL UNIQUE,
|
|
card_type VARCHAR(50),
|
|
customer_id INT UNSIGNED NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
INDEX idx_card_number (card_number),
|
|
INDEX idx_customer_id (customer_id),
|
|
FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS transactions (
|
|
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
transaction_date DATETIME NOT NULL,
|
|
batch_number VARCHAR(20) NOT NULL,
|
|
amount DECIMAL(10,2) NOT NULL,
|
|
volume DECIMAL(10,3) NOT NULL,
|
|
price DECIMAL(8,4) NOT NULL,
|
|
quality_code INT NOT NULL,
|
|
quality_name VARCHAR(50) NOT NULL,
|
|
station VARCHAR(20) NOT NULL,
|
|
terminal VARCHAR(10) NOT NULL,
|
|
pump VARCHAR(10) NOT NULL,
|
|
receipt VARCHAR(20) NOT NULL,
|
|
control_number VARCHAR(20),
|
|
card_id INT UNSIGNED NOT NULL,
|
|
customer_id INT UNSIGNED NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
INDEX idx_transaction_date (transaction_date),
|
|
INDEX idx_batch_number (batch_number),
|
|
INDEX idx_card_id (card_id),
|
|
INDEX idx_customer_id (customer_id),
|
|
INDEX idx_station (station),
|
|
FOREIGN KEY (card_id) REFERENCES cards(id),
|
|
FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|