2024-12-26 15:08:43 +00:00
|
|
|
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
|
|
|
|
2024-12-25 15:40:56 +00:00
|
|
|
CREATE TABLE accounts (
|
2024-12-26 15:08:43 +00:00
|
|
|
id integer NOT NULL,
|
|
|
|
name character varying NOT NULL,
|
|
|
|
kind character varying NOT NULL
|
2024-12-25 15:40:56 +00:00
|
|
|
);
|
|
|
|
|
2024-12-26 15:08:43 +00:00
|
|
|
CREATE TABLE transactions (
|
|
|
|
id serial NOT NULL PRIMARY KEY,
|
2024-12-25 15:40:56 +00:00
|
|
|
amount double precision NOT NULL,
|
|
|
|
debit boolean NOT NULL,
|
|
|
|
offset_account integer NOT NULL,
|
|
|
|
account integer NOT NULL,
|
|
|
|
date timestamp without time zone NOT NULL,
|
2024-12-26 15:08:43 +00:00
|
|
|
description character varying
|
2024-12-25 15:40:56 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE users (
|
2024-12-26 15:08:43 +00:00
|
|
|
id UUID NOT NULL PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
|
|
name character varying UNIQUE NOT NULL,
|
|
|
|
password character varying NOT NULL
|
2024-12-25 15:40:56 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
ALTER TABLE ONLY accounts
|
|
|
|
ADD CONSTRAINT accounts_pkey PRIMARY KEY (id);
|
|
|
|
|
2024-12-26 15:08:43 +00:00
|
|
|
ALTER TABLE ONLY transactions
|
2024-12-25 15:40:56 +00:00
|
|
|
ADD CONSTRAINT "Account" FOREIGN KEY (account) REFERENCES accounts(id) NOT VALID;
|
|
|
|
|
2024-12-26 15:08:43 +00:00
|
|
|
ALTER TABLE ONLY transactions
|
2024-12-25 15:40:56 +00:00
|
|
|
ADD CONSTRAINT "Offset" FOREIGN KEY (offset_account) REFERENCES accounts(id) NOT VALID;
|