@golemio/parkings 1.2.6-dev.744189556 → 1.2.6-rc.745576099
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/db/migrations/postgresql/20230112084954-correction_v_parkomats_sales.js +53 -0
- package/db/migrations/postgresql/sqls/20230112084954-correction_v_parkomats_sales-down.sql +17 -0
- package/db/migrations/postgresql/sqls/20230112084954-correction_v_parkomats_sales-up.sql +18 -0
- package/package.json +1 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var dbm;
|
|
4
|
+
var type;
|
|
5
|
+
var seed;
|
|
6
|
+
var fs = require('fs');
|
|
7
|
+
var path = require('path');
|
|
8
|
+
var Promise;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* We receive the dbmigrate dependency from dbmigrate initially.
|
|
12
|
+
* This enables us to not have to rely on NODE_PATH.
|
|
13
|
+
*/
|
|
14
|
+
exports.setup = function(options, seedLink) {
|
|
15
|
+
dbm = options.dbmigrate;
|
|
16
|
+
type = dbm.dataType;
|
|
17
|
+
seed = seedLink;
|
|
18
|
+
Promise = options.Promise;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
exports.up = function(db) {
|
|
22
|
+
var filePath = path.join(__dirname, 'sqls', '20230112084954-correction_v_parkomats_sales-up.sql');
|
|
23
|
+
return new Promise( function( resolve, reject ) {
|
|
24
|
+
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
|
|
25
|
+
if (err) return reject(err);
|
|
26
|
+
console.log('received data: ' + data);
|
|
27
|
+
|
|
28
|
+
resolve(data);
|
|
29
|
+
});
|
|
30
|
+
})
|
|
31
|
+
.then(function(data) {
|
|
32
|
+
return db.runSql(data);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.down = function(db) {
|
|
37
|
+
var filePath = path.join(__dirname, 'sqls', '20230112084954-correction_v_parkomats_sales-down.sql');
|
|
38
|
+
return new Promise( function( resolve, reject ) {
|
|
39
|
+
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
|
|
40
|
+
if (err) return reject(err);
|
|
41
|
+
console.log('received data: ' + data);
|
|
42
|
+
|
|
43
|
+
resolve(data);
|
|
44
|
+
});
|
|
45
|
+
})
|
|
46
|
+
.then(function(data) {
|
|
47
|
+
return db.runSql(data);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports._meta = {
|
|
52
|
+
"version": 1
|
|
53
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
DROP VIEW v_parkomats_sales;
|
|
2
|
+
|
|
3
|
+
CREATE OR REPLACE VIEW v_parkomats_sales
|
|
4
|
+
AS SELECT date_part('year'::text, parkomats.ticket_bought) AS year,
|
|
5
|
+
"substring"(split_part(parkomats.parking_zone::text, '-'::text, 1), 2, 2) AS parking_zone,
|
|
6
|
+
'Praha '::text || "substring"(split_part(parkomats.parking_zone::text, '-'::text, 1), 2, 2) AS city_district,
|
|
7
|
+
CASE
|
|
8
|
+
WHEN parkomats.channel::text = 'PARKMACHINE'::text THEN 'Parkovací automat'::text
|
|
9
|
+
ELSE 'VPH'::text
|
|
10
|
+
END AS channel,
|
|
11
|
+
sum(parkomats.price) AS sale
|
|
12
|
+
FROM parkomats
|
|
13
|
+
GROUP BY (date_part('year'::text, parkomats.ticket_bought)), ("substring"(split_part(parkomats.parking_zone::text, '-'::text, 1), 2, 2)), ('Praha '::text || "substring"(split_part(parkomats.parking_zone::text, '-'::text, 1), 2, 2)), (
|
|
14
|
+
CASE
|
|
15
|
+
WHEN parkomats.channel::text = 'PARKMACHINE'::text THEN 'Parkovací automat'::text
|
|
16
|
+
ELSE 'VPH'::text
|
|
17
|
+
END);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
DROP VIEW v_parkomats_sales;
|
|
2
|
+
|
|
3
|
+
CREATE OR REPLACE VIEW v_parkomats_sales
|
|
4
|
+
AS SELECT count(parkomats.transaction_id) AS nu_tickets,
|
|
5
|
+
date_part('year'::text, parkomats.ticket_bought) AS year,
|
|
6
|
+
"substring"(split_part(parkomats.parking_zone::text, '-'::text, 1), 2, 2) AS parking_zone,
|
|
7
|
+
'Praha '::text || "substring"(split_part(parkomats.parking_zone::text, '-'::text, 1), 2, 2) AS city_district,
|
|
8
|
+
CASE
|
|
9
|
+
WHEN parkomats.channel::text = 'PARKMACHINE'::text THEN 'Parkovací automat'::text
|
|
10
|
+
ELSE 'VPH'::text
|
|
11
|
+
END AS channel,
|
|
12
|
+
sum(parkomats.price) AS sale
|
|
13
|
+
FROM parkomats
|
|
14
|
+
GROUP BY (date_part('year'::text, parkomats.ticket_bought)), ("substring"(split_part(parkomats.parking_zone::text, '-'::text, 1), 2, 2)), ('Praha '::text || "substring"(split_part(parkomats.parking_zone::text, '-'::text, 1), 2, 2)), (
|
|
15
|
+
CASE
|
|
16
|
+
WHEN parkomats.channel::text = 'PARKMACHINE'::text THEN 'Parkovací automat'::text
|
|
17
|
+
ELSE 'VPH'::text
|
|
18
|
+
END);
|