-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(audit-service): fixed package version in lock file, added migrat…
…ions MIGRATION CHANGE: migration-20210423140543- added migrations for init schema gh-0
- Loading branch information
1 parent
7a332d8
commit c8e9540
Showing
11 changed files
with
7,263 additions
and
9,108 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
13,675 changes: 5,942 additions & 7,733 deletions
13,675
sandbox/workflow-ms-example/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
node_modules/ | ||
dist/ | ||
coverage/ | ||
|
||
migrations/ | ||
migration.js | ||
.eslintrc.js |
Empty file.
This file contains 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,22 @@ | ||
{ | ||
"defaultEnv": "master", | ||
"master": { | ||
"driver": "pg", | ||
"host": { | ||
"ENV": "DB_HOST" | ||
}, | ||
"port": { | ||
"ENV": "DB_PORT" | ||
}, | ||
"user": { | ||
"ENV": "DB_USER" | ||
}, | ||
"password": { | ||
"ENV": "DB_PASSWORD" | ||
}, | ||
"database": { | ||
"ENV": "DB_DATABASE" | ||
} | ||
}, | ||
"sql-file": true | ||
} |
This file contains 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,72 @@ | ||
const dotenv = require('dotenv'); | ||
const dotenvExt = require('dotenv-extended'); | ||
const fs = require('fs'); | ||
const DBMigrate = require('db-migrate'); | ||
const path = require('path'); | ||
let isLocal = false; | ||
dotenv.config({path: path.join(process.env.INIT_CWD, '.env')}); | ||
|
||
try { | ||
if (fs.existsSync('.infolder')) { | ||
isLocal = true; | ||
} | ||
} catch (err) { | ||
console.info('\n'); | ||
} | ||
if ( | ||
isLocal || | ||
process.env.AUDIT_MIGRATION_SKIP || | ||
process.env.SOURCELOOP_MIGRATION_SKIP | ||
) { | ||
console.info(`Skipping migrations`); | ||
} else { | ||
dotenvExt.load({ | ||
schema: path.join(`.`, `migrations`, `.env.schema`), | ||
path: path.join(process.env.INIT_CWD, '.env'), | ||
errorOnMissing: true, | ||
includeProcessEnv: true, | ||
}); | ||
const dbmigrate = DBMigrate.getInstance(true); | ||
dbmigrate.up(); | ||
} | ||
|
||
if (process.env.SOURCELOOP_MIGRATION_COPY || process.env.AUDIT_MIGRATION_COPY) { | ||
copyFileSync(path.join('.', 'database.json'), process.env.INIT_CWD); | ||
copyFolderRecursiveSync(path.join('.', '/migrations'), process.env.INIT_CWD); | ||
} | ||
|
||
function copyFileSync(source, target) { | ||
var targetFile = target; | ||
|
||
// If target is a directory, a new file with the same name will be created | ||
if (fs.existsSync(target)) { | ||
if (fs.lstatSync(target).isDirectory()) { | ||
targetFile = path.join(target, path.basename(source)); | ||
} | ||
} | ||
|
||
fs.writeFileSync(targetFile, fs.readFileSync(source)); | ||
} | ||
|
||
function copyFolderRecursiveSync(source, target) { | ||
var files = []; | ||
|
||
// Check if folder needs to be created or integrated | ||
var targetFolder = path.join(target, path.basename(source)); | ||
if (!fs.existsSync(targetFolder)) { | ||
fs.mkdirSync(targetFolder); | ||
} | ||
|
||
// Copy | ||
if (fs.lstatSync(source).isDirectory()) { | ||
files = fs.readdirSync(source); | ||
files.forEach(function (file) { | ||
var curSource = path.join(source, file); | ||
if (fs.lstatSync(curSource).isDirectory()) { | ||
copyFolderRecursiveSync(curSource, targetFolder); | ||
} else { | ||
copyFileSync(curSource, targetFolder); | ||
} | ||
}); | ||
} | ||
} |
This file contains 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,50 @@ | ||
'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. | ||
*/ | ||
|
||
function handleFile(filePath, resolve, reject) { | ||
fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { | ||
if (err) return reject(err); | ||
console.log('received data: ' + data); | ||
|
||
resolve(data); | ||
}); | ||
} | ||
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', '20210423140543-init-up.sql'); | ||
return new Promise(function (resolve, reject) { | ||
handleFile(filePath, resolve, reject); | ||
}).then(function (data) { | ||
return db.runSql(data); | ||
}); | ||
}; | ||
|
||
exports.down = function (db) { | ||
var filePath = path.join(__dirname, 'sqls', '20210423140543-init-down.sql'); | ||
return new Promise(function (resolve, reject) { | ||
handleFile(filePath, resolve, reject); | ||
}).then(function (data) { | ||
return db.runSql(data); | ||
}); | ||
}; | ||
|
||
exports._meta = { | ||
version: 1, | ||
}; |
1 change: 1 addition & 0 deletions
1
services/audit-service/migrations/sqls/20210423140543-init-down.sql
This file contains 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 @@ | ||
DROP SCHEMA IF EXISTS main CASCADE; |
27 changes: 27 additions & 0 deletions
27
services/audit-service/migrations/sqls/20210423140543-init-up.sql
This file contains 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,27 @@ | ||
DROP SCHEMA IF EXISTS main CASCADE; | ||
CREATE SCHEMA main; | ||
|
||
SET search_path TO main,public; | ||
GRANT ALL ON SCHEMA main TO public; | ||
|
||
CREATE TABLE main.audit_logs ( | ||
id uuid DEFAULT md5(random()::text || clock_timestamp()::text)::uuid NOT NULL , | ||
"action" text NOT NULL, | ||
acted_at timestamptz NOT NULL, | ||
acted_on text NULL, | ||
action_key text NOT NULL, | ||
entity_id text NOT NULL, | ||
actor text NOT NULL, | ||
"before" text NULL, | ||
"after" text NULL, | ||
action_group text NULL, | ||
CONSTRAINT audit_logs_pkey PRIMARY KEY (id) | ||
); | ||
|
||
CREATE TABLE main.todo ( | ||
id uuid DEFAULT md5(random()::text || clock_timestamp()::text)::uuid NOT NULL , | ||
title text NOT NULL, | ||
description text NOT NULL, | ||
items text NULL, | ||
CONSTRAINT todo_pkey PRIMARY KEY (id) | ||
); |
Oops, something went wrong.