Skip to content

Commit

Permalink
Edit sql, create new sql file with hooks.
Browse files Browse the repository at this point in the history
@i didn't found how disable transaction
  • Loading branch information
stasbamiza committed Oct 21, 2016
1 parent 57a5ec5 commit 937ae99
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
14 changes: 2 additions & 12 deletions modules/core/src/main/resources/db/migration/1472473094.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ if ($Dashboard.size() == 0) {

CREATE Class DashboardBoxType EXTENDS OTriggered

console.log "Create functions"

CREATE FUNCTION DashboardBoxTypeFunction "var boxTypeRid = doc.field('@rid'); boxTypeRid = String(boxTypeRid); var functionName = boxTypeRid.replace(/#/g, ''); functionName = functionName.replace(/:/g, '_'); functionName = 'DashboardBoxTypeFunction_' + functionName; db.executeCommand('DELETE FROM OFunction WHERE name = \"'+ functionName +'\"'); code = doc.field('code'); if (code != '') { code = code.replace(/'/g, \"\\'\"); code = code.replace(/\"/g, '\\\\\"'); db.executeCommand('CREATE FUNCTION '+ functionName +' \"'+ code +'\" IDEMPOTENT true LANGUAGE JavaScript'); db.executeCommand('UPDATE DashboardBoxType SET onAfterUpdate = \"'+ functionName +'\" WHERE @rid = '+ boxTypeRid); print('Update'); }" LANGUAGE Javascript
ALTER CLASS DashboardBoxType CUSTOM onAfterDelete=DashboardBoxTypeDeleteFunction "var boxTypeRid = doc.field('@rid'); boxTypeRid = String(boxTypeRid); var functionName = boxTypeRid.replace(/#/g, ''); functionName = functionName.replace(/:/g, '_'); functionName = 'DashboardBoxTypeFunction_' + functionName; db.executeCommand('DELETE FROM OFunction WHERE name = \"'+ functionName +'\"');" LANGUAGE Javascript

ALTER CLASS DashboardBoxType CUSTOM onAfterUpdate = DashboardBoxTypeFunction;
ALTER CLASS DashboardBoxType CUSTOM onAfterDelete=DashboardBoxTypeDeleteFunction

console.log "End create functions"

CREATE PROPERTY DashboardBoxType.name STRING
CREATE PROPERTY DashboardBoxType.type STRING
CREATE PROPERTY DashboardBoxType.kind STRING
Expand All @@ -54,8 +44,8 @@ if ($Dashboard.size() == 0) {
CREATE INDEX DashboardBoxType.name UNIQUE

let statusType = INSERT INTO DashboardBoxType SET name = 'Ivan feeds', type = 'status', kind = 'Feedback status', code = '', codeLanguage = 'SQL'
let pieChartType = INSERT INTO DashboardBoxType SET name = 'Petia profit', type = 'chart', kind = 'Pie chart', code = "return {data: \"[ { 'country': 'Lithuania', 'litres': 501.9 }, { 'country': 'Czech Republic', 'litres': 301.9 }, { 'country': 'Ireland', 'litres': 201.1 }, { 'country': 'Germany', 'litres': 165.8 }, { 'country': 'Australia', 'litres': 139.9 }, { 'country': 'Austria', 'litres': 128.3 }, { 'country': 'UK', 'litres': 99 }, { 'country': 'Belgium', 'litres': 60 }, { 'country': 'The Netherlands', 'litres': 50 } ]\"}", codeLanguage = 'JavaScript'
let serialChartType = INSERT INTO DashboardBoxType SET name = 'Rusia chart profit', type = 'chart', kind = 'Serial chart', code = "return {data: \"[{ date: new Date(2012, 11), value: 0, value0: 0 }, { date: new Date(2013, 0), value: 15000, value0: 19000 }, { date: new Date(2013, 1), value: 30000, value0: 20000 }, { date: new Date(2013, 2), value: 25000, value0: 22000 }, { date: new Date(2013, 3), value: 21000, value0: 25000 }, { date: new Date(2013, 4), value: 24000, value0: 29000 }, { date: new Date(2013, 5), value: 31000, value0: 26000 }, { date: new Date(2013, 6), value: 40000, value0: 25000 }, { date: new Date(2013, 7), value: 37000, value0: 20000 }, { date: new Date(2013, 8), value: 18000, value0: 22000 }, { date: new Date(2013, 9), value: 5000, value0: 26000 }, { date: new Date(2013, 10), value: 40000, value0: 30000 }, { date: new Date(2013, 11), value: 20000, value0: 25000 }, { date: new Date(2014, 0), value: 5000, value0: 13000 }, { date: new Date(2014, 1), value: 3000, value0: 13000 }, { date: new Date(2014, 2), value: 1800, value0: 13000 }, { date: new Date(2014, 3), value: 10400, value0: 13000 }, { date: new Date(2014, 4), value: 25500, value0: 13000 }, { date: new Date(2014, 5), value: 2100, value0: 13000 }, { date: new Date(2014, 6), value: 6500, value0: 13000 }, { date: new Date(2014, 7), value: 1100, value0: 13000 }, { date: new Date(2014, 8), value: 17200, value0: 13000 }, { date: new Date(2014, 9), value: 26900, value0: 13000 }, { date: new Date(2014, 10), value: 14100, value0: 13000 }, { date: new Date(2014, 11), value: 35300, value0: 13000 }, { date: new Date(2015, 0), value: 54800, value0: 13000 }, { date: new Date(2015, 1), value: 49800, value0: 13000 }]\"}", codeLanguage = 'JavaScript'
let pieChartType = INSERT INTO DashboardBoxType SET name = 'Petia profit', type = 'chart', kind = 'Pie chart', code = "return {data: \"function generateStr() { var text = ''; var possible = 'abcdefghijklmnopqrstuvwxyz'; for( var i=0; i < 5; i++ ) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } var res = []; var len = Math.ceil(Math.random()*15); for(var i = 0; i < len; i++) { res.push({ country: generateStr(), litres: Math.ceil(Math.random()*100) }); } res;\"}", codeLanguage = 'JavaScript'
let serialChartType = INSERT INTO DashboardBoxType SET name = 'Rusia chart profit', type = 'chart', kind = 'Serial chart', code = "return {data: \"let res = []; for (let i = 1; i <= 12; i++) { for (let y = 1; y <= 2; y++) { res.push({ date: new Date(2016, i, y*5), value: Math.ceil(Math.random()*1000), value0: Math.ceil(Math.random()*1000) }); } } res;\"}", codeLanguage = 'JavaScript'

console.log "Creating process for DashboardBoxType class is done."
}
Expand Down
9 changes: 9 additions & 0 deletions modules/core/src/main/resources/db/migration/1477044505.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
console.log "Create functions"

CREATE FUNCTION DashboardBoxTypeFunction "var boxTypeRid = doc.field('@rid'); boxTypeRid = String(boxTypeRid); var functionName = boxTypeRid.replace(/#/g, ''); functionName = functionName.replace(/:/g, '_'); functionName = 'DashboardBoxTypeFunction_' + functionName; db.executeCommand('DELETE FROM OFunction WHERE name = \"'+ functionName +'\"'); code = doc.field('code'); if (code != '') { code = code.replace(/'/g, \"\\'\"); code = code.replace(/\"/g, '\\\\\"'); db.executeCommand('CREATE FUNCTION '+ functionName +' \"'+ code +'\" IDEMPOTENT true LANGUAGE JavaScript'); db.executeCommand('UPDATE DashboardBoxType SET onAfterUpdate = \"'+ functionName +'\" WHERE @rid = '+ boxTypeRid); print('Update'); }" LANGUAGE Javascript
CREATE FUNCTION DashboardBoxTypeDeleteFunction "var boxTypeRid = doc.field('@rid'); boxTypeRid = String(boxTypeRid); var functionName = boxTypeRid.replace(/#/g, ''); functionName = functionName.replace(/:/g, '_'); functionName = 'DashboardBoxTypeFunction_' + functionName; db.executeCommand('DELETE FROM OFunction WHERE name = \"'+ functionName +'\"');" LANGUAGE Javascript

ALTER CLASS DashboardBoxType CUSTOM onAfterUpdate = DashboardBoxTypeFunction;
ALTER CLASS DashboardBoxType CUSTOM onAfterDelete=DashboardBoxTypeDeleteFunction

console.log "End create functions"

0 comments on commit 937ae99

Please sign in to comment.