Skip to content

Commit

Permalink
Yotas Migrations (#15)
Browse files Browse the repository at this point in the history
* feat(backend): writing migrations

* feat(backend): migrations - Updates fields

* feat(backend): [2]migrations - Updates fields

* fix(backend): Applying PR-updates from comments

* fix(backend): [2]Applying PR-updates from comments

* fix(backend): [3]Applying PR-updates from comments
  • Loading branch information
Sanix-Darker authored May 24, 2021
1 parent e844fb1 commit e818b97
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.history
dist
build
145 changes: 145 additions & 0 deletions backend/migrations/001_initial.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
-- +goose Up

-- +goose StatementBegin
CREATE TABLE IF NOT EXISTS organisations (
id INT NOT NULL AUTO_INCREMENT,

`name` VARCHAR(150),
email VARCHAR(150) NOT NULL,
github_id VARCHAR(150) NOT NULL,
avatar_url VARCHAR(300),
web_site VARCHAR(300),
`description` VARCHAR(300),

created_at TIMESTAMP,
updated_at TIMESTAMP,

UNIQUE(email, github_id),
PRIMARY KEY(Id)
);

CREATE TABLE IF NOT EXISTS users (
id INT NOT NULL AUTO_INCREMENT,

`name` VARCHAR(150),
email VARCHAR(150) NOT NULL,
github_id VARCHAR(150) NOT NULL,
avatar_url VARCHAR(300),

created_at TIMESTAMP,
updated_at TIMESTAMP,

UNIQUE(email, github_id),
PRIMARY KEY(Id)
);

CREATE TABLE IF NOT EXISTS wallets (
id INT NOT NULL AUTO_INCREMENT,

wallet_id VARCHAR(300) NOT NULL,
user_id INT NOT NULL,
organisation_id INT NOT NULL,
balance INT NOT NULL,

created_at TIMESTAMP,
updated_at TIMESTAMP,

UNIQUE(id, wallet_id),
PRIMARY KEY(Id),
FOREIGN KEY (user_id) REFERENCES Users(user_id),
FOREIGN KEY (organisation_id) REFERENCES Organisations(organisation_id)
);

CREATE TABLE IF NOT EXISTS articles (
id INT NOT NULL AUTO_INCREMENT,

`name` VARCHAR(150),
`description` TEXT,
quantity INTEGER,
price INT NOT NULL,
metadata TEXT,

created_at TIMESTAMP,
updated_at TIMESTAMP,

UNIQUE(id),
PRIMARY KEY(Id)
);

CREATE TABLE IF NOT EXISTS orders (
id INT NOT NULL AUTO_INCREMENT,

wallet_id VARCHAR(300),
article_id INT NOT NULL,
quantity INTEGER,

created_at TIMESTAMP,
updated_at TIMESTAMP,

UNIQUE(id),
PRIMARY KEY(Id),
FOREIGN KEY (wallet_id) REFERENCES Wallets(wallet_id),
FOREIGN KEY (article_id) REFERENCES Articles(article_id)
);

CREATE TABLE IF NOT EXISTS organisations_articles (
id INT NOT NULL AUTO_INCREMENT,

organisation_id INT NOT NULL,
article_id INT NOT NULL,

created_at TIMESTAMP,
updated_at TIMESTAMP,

UNIQUE(id),
PRIMARY KEY(Id),
FOREIGN KEY (organisation_id) REFERENCES Organisations(organisation_id),
FOREIGN KEY (article_id) REFERENCES Articles(article_id)
);

CREATE TABLE IF NOT EXISTS organisations_users (
id INT NOT NULL AUTO_INCREMENT,

organisation_id INT NOT NULL,
user_id INT NOT NULL,
active BOOLEAN,

created_at TIMESTAMP,
updated_at TIMESTAMP,

UNIQUE(id),
PRIMARY KEY(Id),
FOREIGN KEY (organisation_id) REFERENCES Organisations(organisation_id),
FOREIGN KEY (user_id) REFERENCES Users(user_id)
);

CREATE TABLE IF NOT EXISTS operations (
id INT NOT NULL AUTO_INCREMENT,

amount INT NOT NULL,
wallet_id VARCHAR(300),
operation_type ENUM ('buy','receive'),
approuved BOOLEAN,
operation_hash TEXT,

created_at TIMESTAMP,

UNIQUE(operation_hash),
PRIMARY KEY(Id)
FOREIGN KEY (wallet_id) REFERENCES Wallets(wallet_id),
);

-- +goose StatementEnd

-- +goose Down

-- +goose StatementBegin
DROP TABLE organisations;
DROP TABLE users;
DROP TABLE wallets;
DROP TABLE articles;
DROP TABLE orders;
DROP TABLE organisations_articles;
DROP TABLE organisations_users;
DROP TABLE operations;
-- +goose StatementEnd

0 comments on commit e818b97

Please sign in to comment.