-
Notifications
You must be signed in to change notification settings - Fork 0
Add files via upload #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vano7577
wants to merge
1
commit into
main
Choose a base branch
from
vano7577-patch-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
|
|
||
| SET default_tablespace = ts_lemon; | ||
| CREATE EXTENSION IF NOT EXISTS pgcrypto; | ||
| CREATE TABLE IF NOT EXISTS accounts | ||
| ( | ||
| account_id serial PRIMARY KEY, | ||
| account_name varchar(255) NOT NULL, | ||
| login varchar(100) NOT NULL, | ||
| password varchar NOT NULL | ||
| ); | ||
|
|
||
| CREATE UNIQUE INDEX IF NOT EXISTS iu_accounts$login ON accounts (login) TABLESPACE ts_lemon_indexes; | ||
|
|
||
| ALTER TABLE accounts | ||
| ADD CONSTRAINT ch_accounts$login | ||
| CHECK (login ~ '^\S+$'); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS banks | ||
| ( | ||
| bank_id smallserial PRIMARY KEY, | ||
| bank_name varchar(255) NOT NULL UNIQUE | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS cards | ||
| ( | ||
| card_id serial PRIMARY KEY, | ||
| bank_id smallint NOT NULL, | ||
| account_id int NOT NULL, | ||
| card_num smallint NOT NULL, | ||
| type varchar(255) DEFAULT NULL, | ||
| balance int NOT NULL, | ||
| currency char(3) NOT NULL | ||
| ); | ||
| CREATE UNIQUE INDEX IF NOT EXISTS iu_accounts$account_id_card_num ON accounts (login) TABLESPACE ts_lemon_indexes; | ||
| ALTER TABLE cards | ||
| ADD CONSTRAINT ch_len_cards$card_num | ||
| CHECK (CHAR_LENGTH(card_num::text) BETWEEN 4 AND 16), | ||
| ADD CONSTRAINT ch_cards$currency | ||
| CHECK ( CHAR_LENGTH(currency) = 3 AND currency ~ '^\D+$'), | ||
| ADD CONSTRAINT ch_not_negative | ||
| CHECK ( card_num >= 0 ), | ||
| ADD CONSTRAINT fk_cards$bank_id | ||
| FOREIGN KEY (bank_id) | ||
| REFERENCES banks (bank_id) ON DELETE CASCADE ON UPDATE CASCADE, | ||
| ADD CONSTRAINT fk_cards$account_id | ||
| FOREIGN KEY (account_id) | ||
| REFERENCES accounts (account_id) ON DELETE CASCADE ON UPDATE CASCADE | ||
| ; | ||
|
|
||
| CREATE INDEX IF NOT EXISTS bank_idx ON cards (bank_id) TABLESPACE ts_lemon_indexes; | ||
| CREATE INDEX IF NOT EXISTS account_idx ON cards (account_id) TABLESPACE ts_lemon_indexes; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS transactions | ||
| ( | ||
| transaction_id serial PRIMARY KEY, | ||
| card_id int DEFAULT NULL, | ||
| amount int NOT NULL, | ||
| type varchar(255) DEFAULT NULL, | ||
| transaction_datetime timestamptz DEFAULT NULL | ||
| ); | ||
| ALTER TABLE transactions | ||
| ADD CONSTRAINT fk_transactions$card_id | ||
| FOREIGN KEY (card_id) REFERENCES cards (card_id) ON DELETE CASCADE ON UPDATE CASCADE, | ||
| ADD CONSTRAINT ch_transactions$transaction_datetime | ||
| CHECK ( EXTRACT(YEAR FROM transaction_datetime) >=1951 ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS types | ||
| ( | ||
| type_id smallserial PRIMARY KEY, | ||
| type_name varchar(100) NOT NULL UNIQUE | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS connection | ||
| ( | ||
| connection_id serial PRIMARY KEY, | ||
| card_id int NOT NULL, | ||
| type_id smallint NOT NULL, | ||
| value varchar NOT NULL | ||
| ); | ||
| ALTER TABLE connection | ||
| ADD CONSTRAINT fk_connection$card_id | ||
| FOREIGN KEY (card_id) REFERENCES cards (card_id) ON DELETE CASCADE ON UPDATE CASCADE, | ||
| ADD CONSTRAINT fk_connection$type_id | ||
| FOREIGN KEY (type_id) REFERENCES types (type_id) ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| CREATE INDEX IF NOT EXISTS type_idx ON connection (type_id) TABLESPACE ts_lemon_indexes; | ||
| CREATE INDEX IF NOT EXISTS card_idx ON connection (card_id) TABLESPACE ts_lemon_indexes; | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.