-- +goose Up
-- +goose StatementBegin

-- create table orders
CREATE TABLE
    orders (
        id SERIAL8 PRIMARY KEY,
        created_at timestamp NOT NULL default now(),
        updated_at timestamp NOT NULL default now(),
        deleted_at timestamp,

        tenant_id INT8 NOT NULL,
        user_id INT8 NOT NULL,

        type INT2 NOT NULL default 0,
        status INT2 NOT NULL default 0,
        order_serial VARCHAR(64) NOT NULL UNIQUE,
        remote_order_serial VARCHAR(256) NOT NULL UNIQUE,
        refund_serial VARCHAR(64) NOT NULL UNIQUE,
        remote_refund_serial VARCHAR(256) NOT NULL UNIQUE,
        amount INT8 NOT NULL default 0,
        currency VARCHAR(32) NOT NULL default 'CNY',
        description VARCHAR(256),
        meta jsonb default '{}'::jsonb
    );
-- create indexes
CREATE INDEX idx_orders_tenant_id ON orders(tenant_id);
CREATE INDEX idx_orders_user_id ON orders(user_id);
CREATE INDEX idx_orders_order_serial ON orders(order_serial);
CREATE INDEX idx_orders_remote_order_serial ON orders(remote_order_serial);


-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
DROP TABLE orders;
-- +goose StatementEnd
