CREATE TYPE transaction_type_enum as ENUM ('expense', 'income');
DROP TABLE IF EXISTS category;
CREATE TABLE category (
id SERIAL PRIMARY KEY,
name VARCHAR(100) UNIQUE NOT NULL,
type transaction_type_enum DEFAULT 'expense' NOT NULL,
CONSTRAINT unique_category_type UNIQUE (id, type)
);
DROP TABLE IF EXISTS transaction;
CREATE TABLE transaction (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
label VARCHAR(128),
amount INT NOT NULL,
categoryid INT REFERENCES category(id),
type transaction_type_enum DEFAULT 'expense' NOT NULL,
FOREIGN KEY (categoryid, type) REFERENCES category(id, type)
DEFERRABLE INITIALLY DEFERRED
);
CREATE TYPE transaction_type_enum as ENUM ('expense', 'income');
DROP TABLE IF EXISTS category;
CREATE TABLE category (
id SERIAL PRIMARY KEY,
name VARCHAR(100) UNIQUE NOT NULL,
type transaction_type_enum DEFAULT 'expense' NOT NULL,
CONSTRAINT unique_category_type UNIQUE (id, type)
);
DROP TABLE IF EXISTS transaction;
CREATE TABLE transaction (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
label VARCHAR(128),
amount INT NOT NULL,
categoryid INT REFERENCES category(id),
type transaction_type_enum DEFAULT 'expense' NOT NULL,
FOREIGN KEY (categoryid, type) REFERENCES category(id, type)
DEFERRABLE INITIALLY DEFERRED
);