Supports dashboard CRUD and tenant list/get/calculate so storefronts can offer installments, requiring a method pick when several exist. Co-authored-by: Cursor <cursoragent@cursor.com>
38 lines
1.4 KiB
SQL
38 lines
1.4 KiB
SQL
-- Store loan / installment methods (اقساط و تسهیلات)
|
|
|
|
CREATE TABLE IF NOT EXISTS store_loan_methods (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
business_id BIGINT NOT NULL REFERENCES businesses (id) ON DELETE CASCADE ON UPDATE NO ACTION,
|
|
name VARCHAR(255) NOT NULL,
|
|
name_en VARCHAR(255) NOT NULL,
|
|
description TEXT NULL,
|
|
image_media_id BIGINT NULL REFERENCES media (id) ON UPDATE NO ACTION,
|
|
image_aspect_ratio VARCHAR(10) NOT NULL DEFAULT '1:1',
|
|
min_shopping_amount NUMERIC(12, 2) NOT NULL,
|
|
min_amount NUMERIC(12, 2) NOT NULL,
|
|
max_amount NUMERIC(12, 2) NOT NULL,
|
|
interest NUMERIC(8, 4) NOT NULL,
|
|
return_months_min INT NOT NULL,
|
|
return_months_max INT NOT NULL,
|
|
return_months_step INT NOT NULL DEFAULT 3,
|
|
sort_order INT NOT NULL DEFAULT 0,
|
|
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_store_loan_methods_business_id
|
|
ON store_loan_methods (business_id);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_store_loan_methods_image_media_id
|
|
ON store_loan_methods (image_media_id);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_store_loan_methods_business_sort_order
|
|
ON store_loan_methods (business_id, sort_order);
|
|
|
|
DROP TRIGGER IF EXISTS store_loan_methods_set_updated_at ON store_loan_methods;
|
|
CREATE TRIGGER store_loan_methods_set_updated_at
|
|
BEFORE UPDATE ON store_loan_methods
|
|
FOR EACH ROW
|
|
EXECUTE FUNCTION set_updated_at();
|