mirror of
https://github.com/Example-uPagge/transactional.git
synced 2024-06-14 11:52:55 +03:00
Добавил SQL запросы
This commit is contained in:
parent
6db3ee42e4
commit
b9dd311fb5
23
sql/create-tables.sql
Normal file
23
sql/create-tables.sql
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
CREATE SEQUENCE seq_person;
|
||||||
|
CREATE SEQUENCE seq_transaction;
|
||||||
|
|
||||||
|
CREATE TABLE person
|
||||||
|
(
|
||||||
|
id BIGINT NOT NULL PRIMARY KEY DEFAULT nextval('seq_person'),
|
||||||
|
balance BIGINT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE transaction
|
||||||
|
(
|
||||||
|
id BIGINT NOT NULL PRIMARY KEY DEFAULT nextval('seq_transaction'),
|
||||||
|
person_from BIGINT NOT NULL REFERENCES person (id),
|
||||||
|
person_to BIGINT NOT NULL REFERENCES person (id),
|
||||||
|
amount BIGINT NOT NULL
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO person
|
||||||
|
VALUES (1, 1000);
|
||||||
|
|
||||||
|
INSERT INTO person
|
||||||
|
VALUES (2, 1000);
|
7
sql/drop-tables.sql
Normal file
7
sql/drop-tables.sql
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
drop table transaction cascade;
|
||||||
|
|
||||||
|
drop table person cascade;
|
||||||
|
|
||||||
|
drop sequence seq_person;
|
||||||
|
|
||||||
|
drop sequence seq_transaction;
|
6
sql/fail-transaction.sql
Normal file
6
sql/fail-transaction.sql
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
INSERT INTO person values (1, 100);
|
||||||
|
INSERT INTO person values (2, 100);
|
||||||
|
|
||||||
|
UPDATE person SET balance = (balance - 10) WHERE id = 1;
|
||||||
|
INSERT INTO transaction(person_from, person_to, amount) values (1, 3, 10);
|
||||||
|
UPDATE person SET balance = (balance + 10) WHERE id = 2;
|
3
sql/refresh-balance.sql
Normal file
3
sql/refresh-balance.sql
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
DELETE FROM person WHERE id = 3;
|
||||||
|
DELETE FROM transaction;
|
||||||
|
UPDATE person SET balance = 1000 WHERE id in (1,2)
|
10
sql/success-transaction.sql
Normal file
10
sql/success-transaction.sql
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
UPDATE person SET balance=100 WHERE id IN (1,2);
|
||||||
|
DELETE FROM transaction WHERE person_from = 1;
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
UPDATE person SET balance = (balance - 10) WHERE id = 1;
|
||||||
|
INSERT INTO transaction(person_from, person_to, amount) values (1, 3, 10);
|
||||||
|
UPDATE person SET balance = (balance + 10) WHERE id = 2;
|
||||||
|
|
||||||
|
COMMIT;
|
Loading…
x
Reference in New Issue
Block a user