Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
58ef17be
Commit
58ef17be
authored
9 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
Added automated database migration script
parent
553e7fb8
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/lib/dal/fileDAL.js
+5
-0
5 additions, 0 deletions
app/lib/dal/fileDAL.js
app/lib/dal/sqliteDAL/MetaDAL.js
+61
-0
61 additions, 0 deletions
app/lib/dal/sqliteDAL/MetaDAL.js
test/dal/dal.js
+6
-0
6 additions, 0 deletions
test/dal/dal.js
with
72 additions
and
0 deletions
app/lib/dal/fileDAL.js
+
5
−
0
View file @
58ef17be
...
@@ -33,6 +33,7 @@ function FileDAL(params) {
...
@@ -33,6 +33,7 @@ function FileDAL(params) {
// DALs
// DALs
this
.
confDAL
=
new
ConfDAL
(
rootPath
,
myFS
,
null
,
that
,
CFSStorage
);
this
.
confDAL
=
new
ConfDAL
(
rootPath
,
myFS
,
null
,
that
,
CFSStorage
);
this
.
metaDAL
=
new
(
require
(
'
./sqliteDAL/MetaDAL
'
))(
sqlite
);
this
.
peerDAL
=
new
(
require
(
'
./sqliteDAL/PeerDAL
'
))(
sqlite
);
this
.
peerDAL
=
new
(
require
(
'
./sqliteDAL/PeerDAL
'
))(
sqlite
);
this
.
blockDAL
=
new
(
require
(
'
./sqliteDAL/BlockDAL
'
))(
sqlite
);
this
.
blockDAL
=
new
(
require
(
'
./sqliteDAL/BlockDAL
'
))(
sqlite
);
this
.
sourcesDAL
=
new
(
require
(
'
./sqliteDAL/SourcesDAL
'
))(
sqlite
);
this
.
sourcesDAL
=
new
(
require
(
'
./sqliteDAL/SourcesDAL
'
))(
sqlite
);
...
@@ -45,6 +46,7 @@ function FileDAL(params) {
...
@@ -45,6 +46,7 @@ function FileDAL(params) {
this
.
msDAL
=
new
(
require
(
'
./sqliteDAL/MembershipDAL
'
))(
sqlite
);
this
.
msDAL
=
new
(
require
(
'
./sqliteDAL/MembershipDAL
'
))(
sqlite
);
this
.
newDals
=
{
this
.
newDals
=
{
'
metaDAL
'
:
that
.
metaDAL
,
'
blockDAL
'
:
that
.
blockDAL
,
'
blockDAL
'
:
that
.
blockDAL
,
'
certDAL
'
:
that
.
certDAL
,
'
certDAL
'
:
that
.
certDAL
,
'
msDAL
'
:
that
.
msDAL
,
'
msDAL
'
:
that
.
msDAL
,
...
@@ -77,8 +79,11 @@ function FileDAL(params) {
...
@@ -77,8 +79,11 @@ function FileDAL(params) {
this
.
init
=
()
=>
co
(
function
*
()
{
this
.
init
=
()
=>
co
(
function
*
()
{
yield
_
.
values
(
that
.
newDals
).
map
((
dal
)
=>
dal
.
init
());
yield
_
.
values
(
that
.
newDals
).
map
((
dal
)
=>
dal
.
init
());
yield
that
.
metaDAL
.
upgradeDatabase
();
});
});
this
.
getDBVersion
=
()
=>
that
.
metaDAL
.
getVersion
();
this
.
getCurrency
=
function
()
{
this
.
getCurrency
=
function
()
{
return
currency
;
return
currency
;
};
};
...
...
This diff is collapsed.
Click to expand it.
app/lib/dal/sqliteDAL/MetaDAL.js
0 → 100644
+
61
−
0
View file @
58ef17be
/**
* Created by cgeek on 22/08/15.
*/
var
co
=
require
(
'
co
'
);
var
logger
=
require
(
'
../../../../app/lib/logger
'
)(
'
linksDAL
'
);
var
AbstractSQLite
=
require
(
'
./AbstractSQLite
'
);
module
.
exports
=
MetaDAL
;
function
MetaDAL
(
db
)
{
"
use strict
"
;
AbstractSQLite
.
call
(
this
,
db
);
let
that
=
this
;
this
.
table
=
'
meta
'
;
this
.
fields
=
[
'
id
'
,
'
version
'
];
this
.
arrays
=
[];
this
.
booleans
=
[];
this
.
pkFields
=
[
'
version
'
];
this
.
translated
=
{};
let
migrations
=
{
0
:
'
BEGIN; COMMIT;
'
,
1
:
'
BEGIN; COMMIT;
'
};
this
.
init
=
()
=>
co
(
function
*
()
{
return
that
.
exec
(
'
BEGIN;
'
+
'
CREATE TABLE IF NOT EXISTS
'
+
that
.
table
+
'
(
'
+
'
id INTEGER NOT NULL,
'
+
'
version INTEGER NOT NULL,
'
+
'
PRIMARY KEY (id)
'
+
'
);
'
+
'
INSERT INTO
'
+
that
.
table
+
'
VALUES (1,0);
'
+
'
COMMIT;
'
,
[]);
});
this
.
upgradeDatabase
=
()
=>
co
(
function
*
()
{
let
version
=
yield
that
.
getVersion
();
while
(
migrations
[
version
])
{
yield
that
.
exec
(
migrations
[
version
]);
// Automated increment
yield
that
.
exec
(
'
UPDATE meta SET version = version + 1
'
);
version
++
;
}
});
this
.
getRow
=
()
=>
that
.
sqlFindOne
({
id
:
1
});
this
.
getVersion
=
()
=>
co
(
function
*
()
{
let
row
=
yield
that
.
getRow
();
return
row
.
version
;
});
}
This diff is collapsed.
Click to expand it.
test/dal/dal.js
+
6
−
0
View file @
58ef17be
...
@@ -170,6 +170,12 @@ describe("DAL", function(){
...
@@ -170,6 +170,12 @@ describe("DAL", function(){
return
fileDAL
.
saveConf
({
currency
:
"
meta_brouzouf
"
});
return
fileDAL
.
saveConf
({
currency
:
"
meta_brouzouf
"
});
}));
}));
it
(
'
should have DB version 2
'
,
()
=>
co
(
function
*
()
{
let
version
=
yield
fileDAL
.
getDBVersion
();
should
.
exist
(
version
);
version
.
should
.
equal
(
2
);
}));
it
(
'
should have no peer in a first time
'
,
function
(){
it
(
'
should have no peer in a first time
'
,
function
(){
return
fileDAL
.
listAllPeers
().
then
(
function
(
peers
){
return
fileDAL
.
listAllPeers
().
then
(
function
(
peers
){
peers
.
should
.
have
.
length
(
0
);
peers
.
should
.
have
.
length
(
0
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment