Commit 4dd84cad authored by Lucas Fernandes de Oliveira's avatar Lucas Fernandes de Oliveira
Browse files

Issue#59: Fix createSchema.ts and add npm run schema


Signed-off-by: Lucas Fernandes de Oliveira's avatarLucas Fernandes de Oliveira <lfo14@inf.ufpr.br>
parent d7beb242
Pipeline #14374 passed with stages
in 2 minutes and 22 seconds
...@@ -19,3 +19,4 @@ ...@@ -19,3 +19,4 @@
/dist /dist
/database/views /database/views
/service /service
schema.sql
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
"test": "env $(cat config/test.env) ts-node node_modules/istanbul/lib/cli.js cover -x \"**/*.spec.ts\" -e .ts _mocha", "test": "env $(cat config/test.env) ts-node node_modules/istanbul/lib/cli.js cover -x \"**/*.spec.ts\" -e .ts _mocha",
"show-coverage": "xdg-open coverage/lcov-report/index.html", "show-coverage": "xdg-open coverage/lcov-report/index.html",
"doc-api": "raml2html -i specs/blendb-api-v1.raml -o doc/api-v1-reference.html", "doc-api": "raml2html -i specs/blendb-api-v1.raml -o doc/api-v1-reference.html",
"database": "ts-node database/config.ts database", "schema": "env $(cat config/config.env ) ts-node scripts/schema.ts config/config.yaml schema.sql",
"service": "./scripts/service.sh" "service": "./scripts/service.sh"
}, },
"repository": { "repository": {
......
...@@ -52,8 +52,20 @@ for (let i = 0; i < config.buildViews.length; ++i) { ...@@ -52,8 +52,20 @@ for (let i = 0; i < config.buildViews.length; ++i) {
if (view.origin) { if (view.origin) {
// Cria uma tabela // Cria uma tabela
let output = "-- View: " + alias + "\n"; let output = "-- View: " + alias + "\n";
output += "DROP VIEW IF EXISTS view_" + view.id + " CASCADE;\n"; if (process.env.BLENDB_ADAPTER === "postgres") {
output += "CREATE OR REPLACE VIEW view_" + view.id + " AS\n"; output += "DROP VIEW IF EXISTS view_" + view.id + " CASCADE;\n";
output += "CREATE OR REPLACE VIEW view_" + view.id + " AS\n";
}
else if (process.env.BLENDB_ADAPTER === "monet") {
output += "DROP VIEW view_" + view.id + " CASCADE;\n";
output += "CREATE VIEW view_" + view.id + " AS\n";
}
else {
console.log("The adapter value:", process.env.BLENDB_ADAPTER, "is invalid. Abort");
process.exit(1);
}
output += fs.readFileSync(referencePath + "/" + filePath, {encoding: "utf-8" }); output += fs.readFileSync(referencePath + "/" + filePath, {encoding: "utf-8" });
schema += output + "\n"; schema += output + "\n";
engine.addView(view); engine.addView(view);
...@@ -72,10 +84,25 @@ for (let i = 0; i < config.buildViews.length; ++i) { ...@@ -72,10 +84,25 @@ for (let i = 0; i < config.buildViews.length; ++i) {
}); });
const table = adapter.getQueryFromView(materializedView); const table = adapter.getQueryFromView(materializedView);
const query = "-- View: " + alias + "\n" + let query = "-- View: " + alias + "\n";
"DROP MATERIALIZED VIEW IF EXISTS view_" + view.id + " CASCADE;\n" + if (process.env.BLENDB_ADAPTER === "postgres") {
query += "DROP MATERIALIZED VIEW IF EXISTS view_" + view.id + " CASCADE;\n" +
"CREATE MATERIALIZED VIEW view_" + materializedView.id + "CREATE MATERIALIZED VIEW view_" + materializedView.id +
" AS " + table + "\n\n"; " AS " + table + "\n\n";
}
else if (process.env.BLENDB_ADAPTER === "monet") {
console.log("MonetDb does not support Materializaed views. Abort");
console.log("All views in config.yaml must be origin form MonetDB");
console.log("This is a known issue.");
console.log("In the future this script will create a table and copy the data.");
process.exit(1);
}
else {
console.log("The adapter value:", process.env.BLENDB_ADAPTER, "is invalid. Abort");
process.exit(1);
}
schema += query; schema += query;
engine.addView(materializedView); engine.addView(materializedView);
...@@ -88,4 +115,8 @@ fs.writeFile(schemaFile, schema, (error) => { ...@@ -88,4 +115,8 @@ fs.writeFile(schemaFile, schema, (error) => {
process.exitCode = 1; process.exitCode = 1;
return; return;
} }
else {
console.log("File: " + schemaFile + " created");
}
}); });
...@@ -96,9 +96,12 @@ export class ConfigParser { ...@@ -96,9 +96,12 @@ export class ConfigParser {
port: parseInt(process.env.BLENDB_DB_PORT, 10) port: parseInt(process.env.BLENDB_DB_PORT, 10)
}; };
const strCreate = process.env.BLENDB_ST_CREATE;
const strInsert = process.env.BLENDB_ST_INSERT;
let struct: LoadStruct = { let struct: LoadStruct = {
create: process.env.BLENDB_ST_CREATE.toLowerCase() === "true", create: (strCreate) ? strCreate.toLowerCase() === "true" : false,
insert: process.env.BLENDB_ST_INSERT.toLowerCase() === "true" insert: (strInsert) ? strInsert.toLowerCase() === "true" : false
}; };
let metricsOpts = config.metrics; let metricsOpts = config.metrics;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment