Skip to content

Commit

Permalink
Merge pull request #117 from AbsaOSS/wallet/mysql
Browse files Browse the repository at this point in the history
Wallet/mysql
  • Loading branch information
mirgee authored Nov 24, 2021
2 parents c07b92d + 309b143 commit a4e3eaf
Show file tree
Hide file tree
Showing 70 changed files with 7,461 additions and 2,174 deletions.
274 changes: 215 additions & 59 deletions .github/workflows/main.yml

Large diffs are not rendered by default.

22 changes: 8 additions & 14 deletions ci/docker-compose.agency-ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ services:
image: ${AGENCY_IMAGE:-vcxagency:latest}
container_name: agency
logging: *service-logging
depends_on:
- postgres
- redis
environment:
- LOG_JSON_TO_CONSOLE=false
- LOG_LEVEL=info
Expand All @@ -32,20 +29,17 @@ services:
- AGENCY_TYPE=client
- REDIS_URL=redis://redis.absadocker:6379/0

- PG_STORE_HOST=postgres.absadocker
- PG_STORE_PORT=5432
- PG_STORE_ACCOUNT=postgres
- PG_STORE_PASSWORD_SECRET=mysecretpassword
- PG_STORE_DATABASE=storage-ea

- PG_WALLET_ACCOUNT=postgres
- PG_WALLET_PASSWORD_SECRET=mysecretpassword
- PG_WALLET_ADMIN_ACCOUNT=postgres
- PG_WALLET_ADMIN_PASSWORD_SECRET=mysecretpassword
- PG_WALLET_URL=postgres.absadocker:5432
- MYSQL_HOST=mysql.absadocker
- MYSQL_PORT=3306
- MYSQL_ACCOUNT=root
- MYSQL_PASSWORD_SECRET=mysecretpassword
- MYSQL_DATABASE_APPLICATION=agency_application
- MYSQL_DATABASE_WALLET=ca_agency_wallets
- MYSQL_DATABASE_WALLET_CONNECTION_LIMIT=50

- SERVER_ENABLE_TLS=false
networks:
- absadocker
ports:
- "8080:8080"
command: ["sh", "-c", "sleep 5 && npm run serve"]
20 changes: 8 additions & 12 deletions ci/docker-compose.agency-ea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ services:
image: ${AGENCY_IMAGE:-vcxagency:latest}
container_name: agency
logging: *service-logging
depends_on:
- postgres
environment:
- LOG_JSON_TO_CONSOLE=false
- LOG_LEVEL=info
Expand All @@ -30,20 +28,18 @@ services:

- AGENCY_TYPE=enterprise

- PG_STORE_HOST=postgres.absadocker
- PG_STORE_PORT=5432
- PG_STORE_ACCOUNT=postgres
- PG_STORE_PASSWORD_SECRET=mysecretpassword
- PG_STORE_DATABASE=storage-ea

- PG_WALLET_ACCOUNT=postgres
- PG_WALLET_PASSWORD_SECRET=mysecretpassword
- PG_WALLET_ADMIN_ACCOUNT=postgres
- PG_WALLET_ADMIN_PASSWORD_SECRET=mysecretpassword
- PG_WALLET_URL=postgres.absadocker:5432
- MYSQL_HOST=mysql.absadocker
- MYSQL_PORT=3306
- MYSQL_ACCOUNT=root
- MYSQL_PASSWORD_SECRET=mysecretpassword
- MYSQL_DATABASE_APPLICATION=agency_application
- MYSQL_DATABASE_WALLET=ea_agency_wallets
- MYSQL_DATABASE_WALLET_CONNECTION_LIMIT=50

- SERVER_ENABLE_TLS=false
networks:
- absadocker
ports:
- "8080:8080"
command: ["sh", "-c", "sleep 5 && npm run serve"]
12 changes: 12 additions & 0 deletions ci/docker-compose.mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.5'

services:
mysql:
container_name: mysql
image: mysql:5.7.35
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-mysecretpassword}
networks:
- absadocker
ports:
- "3306:3306"
18 changes: 0 additions & 18 deletions ci/docker-compose.pg.yml

This file was deleted.

11 changes: 11 additions & 0 deletions dbutils/database.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"dev": {
"driver": "mysql",
"multipleStatements": true,
"user": { "ENV": "MYSQL_USER" },
"password": { "ENV": "MYSQL_PASSWORD" },
"host": { "ENV": "MYSQL_HOST" },
"port": { "ENV": "MYSQL_PORT" },
"database": { "ENV": "MYSQL_DATABASE" }
}
}
7 changes: 7 additions & 0 deletions dbutils/dev-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export MYSQL_USER=root
export MYSQL_PASSWORD=mysecretpassword
export MYSQL_HOST=localhost
export MYSQL_PORT=3306

MYSQL_DATABASE=agency_wallets npm run schema:migrate:wallet
MYSQL_DATABASE=agency_store npm run schema:migrate:app
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

var dbm;
var type;
var seed;
var fs = require('fs');
var path = require('path');
var Promise;

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
Promise = options.Promise;
};

exports.up = function(db) {
var filePath = path.join(__dirname, 'sqls', '20210914135739-create-tables-up.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
})
.then(function(data) {
return db.runSql(data);
});
};

exports.down = function(db) {
var filePath = path.join(__dirname, 'sqls', '20210914135739-create-tables-down.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
})
.then(function(data) {
return db.runSql(data);
});
};

exports._meta = {
"version": 1
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

var dbm;
var type;
var seed;
var fs = require('fs');
var path = require('path');
var Promise;

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
Promise = options.Promise;
};

exports.up = function(db) {
var filePath = path.join(__dirname, 'sqls', '20210914135810-create-indices-up.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
})
.then(function(data) {
return db.runSql(data);
});
};

exports.down = function(db) {
var filePath = path.join(__dirname, 'sqls', '20210914135810-create-indices-down.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
})
.then(function(data) {
return db.runSql(data);
});
};

exports._meta = {
"version": 1
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Replace with your SQL commands */
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CREATE TABLE entities (
id SERIAL PRIMARY KEY,
entity_did VARCHAR (50),
entity_verkey VARCHAR (50),
entity_record json NOT NULL,
UNIQUE(entity_did),
UNIQUE(entity_verkey)
);

CREATE TABLE messages (
id SERIAL PRIMARY KEY,
agent_did VARCHAR (50),
agent_connection_did VARCHAR (50),
uid VARCHAR (50),
status_code VARCHAR (50),
payload BLOB
);

CREATE TABLE agents (
agent_did VARCHAR (50) PRIMARY KEY,
webhook_url VARCHAR (512),
has_new_message BOOL
);

CREATE TABLE agent_connections (
agent_connection_did VARCHAR (50) PRIMARY KEY,
user_pw_did VARCHAR (50),
agent_did VARCHAR (50)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Replace with your SQL commands */
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE INDEX messages_agent_did ON messages (agent_did);
CREATE INDEX messages_agent_did_agent_conn_did ON messages (agent_did, agent_connection_did);
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

var dbm;
var type;
var seed;
var fs = require('fs');
var path = require('path');
var Promise;

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
Promise = options.Promise;
};

exports.up = function(db) {
var filePath = path.join(__dirname, 'sqls', '20210910105243-create-all-initial-up.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
})
.then(function(data) {
return db.runSql(data);
});
};

exports.down = function(db) {
var filePath = path.join(__dirname, 'sqls', '20210910105243-create-all-initial-down.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
})
.then(function(data) {
return db.runSql(data);
});
};

exports._meta = {
"version": 1
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Replace with your SQL commands */
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE TABLE items (
wallet_id int NOT NULL,
type varchar(256) NOT NULL,
name varchar(256) NOT NULL,
value blob NOT NULL,
tags varchar(256) DEFAULT NULL,
PRIMARY KEY (wallet_id, type, name)
);

CREATE TABLE wallets (
id int NOT NULL AUTO_INCREMENT,
name varchar(64) NOT NULL,
metadata varchar(4096) DEFAULT NULL,
PRIMARY KEY (id)
);
32 changes: 32 additions & 0 deletions dbutils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "dbutils",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"dev:schema:drop:wallet": "MYSQL_DATABASE=agency_wallets node scripts/drop-schema.js",
"dev:schema:drop:app": "MYSQL_DATABASE=agency_application node scripts/drop-schema.js",
"dev:schema:drop:all": "npm run dev:schema:drop:wallet && npm run dev:schema:drop:app",
"dev:schema:migrate:all": "npm run dev:schema:migrate:wallet && npm run dev:schema:migrate:app",
"dev:schema:migrate:wallet": "MYSQL_DATABASE=agency_wallets MYSQL_USER=root MYSQL_PASSWORD=mysecretpassword MYSQL_HOST=localhost MYSQL_PORT=3306 npm run schema:migrate:wallet",
"dev:schema:migrate:app": "MYSQL_DATABASE=agency_application MYSQL_USER=root MYSQL_PASSWORD=mysecretpassword MYSQL_HOST=localhost MYSQL_PORT=3306 npm run schema:migrate:app",
"schema:migrate:wallet": "node scripts/assure-schema.js && db-migrate --migrations-dir migrations_scheme_wallets up",
"schema:migrate:app": "node scripts/assure-schema.js && db-migrate --migrations-dir migrations_scheme_application up",

"migrate:script": "node src/migration.js",

"test": "jest --runInBand ./test"
},
"author": "",
"license": "ISC",
"dependencies": {
"db-migrate": "^0.11.12",
"db-migrate-mysql": "^2.1.2",
"jest": "^27.1.1",
"mysql": "^2.18.1",
"uuid": "^8.3.2"
},
"devDependencies": {
"sleep-promise": "^8.0.1"
}
}
Loading

0 comments on commit a4e3eaf

Please sign in to comment.