Skip to content
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

Yotas Migrations #15

Merged
merged 6 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
146 changes: 146 additions & 0 deletions backend/migrations/001_initial.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
-- +goose Up

-- +goose StatementBegin
CREATE TABLE IF NOT EXISTS Organisations (
gtindo marked this conversation as resolved.
Show resolved Hide resolved
id INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(150),
email VARCHAR(150) NOT NULL,
githubID VARCHAR(150) NOT NULL,
avatarUrl VARCHAR(300),
webSite VARCHAR(300),
`description` VARCHAR(300),

createdAt TIMESTAMP,
updatedAt TIMESTAMP,
deletedAt TIMESTAMP,

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

CREATE TABLE IF NOT EXISTS Users (
id INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(150),
email VARCHAR(150) NOT NULL,
githubID VARCHAR(150) NOT NULL,
avatarUrl VARCHAR(300),

createdAt TIMESTAMP,
updatedAt TIMESTAMP,
deletedAt TIMESTAMP,

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

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

walletID VARCHAR(300) NOT NULL,
gtindo marked this conversation as resolved.
Show resolved Hide resolved
userID INT NOT NULL,
organisationID INT NOT NULL,
balance INT NOT NULL,

createdAt TIMESTAMP,
updatedAt TIMESTAMP,
deletedAt TIMESTAMP,

UNIQUE(walletID),
PRIMARY KEY(Id),
FOREIGN KEY (userID) REFERENCES Users(userID),
FOREIGN KEY (organisationID) REFERENCES Organisations(organisationID)
);

CREATE TABLE IF NOT EXISTS Articles (
id INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(150),
`description` TEXT,
quantity INTEGER,
yotas INT NOT NULL,
gtindo marked this conversation as resolved.
Show resolved Hide resolved
metadata TEXT,

createdAt TIMESTAMP,
updatedAt TIMESTAMP,
deletedAt TIMESTAMP,

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

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

walletID VARCHAR(300),
articleID INT NOT NULL,
quantity INTEGER,

createdAt TIMESTAMP,
updatedAt TIMESTAMP,
deletedAt TIMESTAMP,

UNIQUE(id),
PRIMARY KEY(Id),
FOREIGN KEY (walletID) REFERENCES Wallets(walletID),
FOREIGN KEY (articleID) REFERENCES Articles(articleID)
);

CREATE TABLE IF NOT EXISTS OrganisationsArticles (
id INT NOT NULL AUTO_INCREMENT,
organisationID INT NOT NULL,
articleID INT NOT NULL,

createdAt TIMESTAMP,
updatedAt TIMESTAMP,
deletedAt TIMESTAMP,

UNIQUE(id),
PRIMARY KEY(Id),
FOREIGN KEY (organisationID) REFERENCES Organisations(organisationID),
FOREIGN KEY (articleID) REFERENCES Articles(articleID)
);

CREATE TABLE IF NOT EXISTS OrganisationsUsers (
id INT NOT NULL AUTO_INCREMENT,
organisationID INT NOT NULL,
userID INT NOT NULL,

createdAt TIMESTAMP,
updatedAt TIMESTAMP,
deletedAt TIMESTAMP,

UNIQUE(id),
PRIMARY KEY(Id),
FOREIGN KEY (organisationID) REFERENCES Organisations(organisationID),
FOREIGN KEY (userID) REFERENCES Users(userID)
);

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

yotas INT NOT NULL,
walletID VARCHAR(300),
operationType ENUM ('buy','receive'),
approuved BOOLEAN,
operationHash TEXT,

createdAt TIMESTAMP,

UNIQUE(operationHash),
PRIMARY KEY(Id)
FOREIGN KEY (walletID) REFERENCES Wallets(walletID),
);

-- +goose StatementEnd

-- +goose Down

-- +goose StatementBegin
DROP TABLE Organisations;
DROP TABLE Users;
DROP TABLE Wallets;
DROP TABLE Articles;
DROP TABLE Orders;
DROP TABLE OrganisationsArticles;
DROP TABLE OrganisationsUsers;
DROP TABLE Operations;
-- +goose StatementEnd