Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
persona
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hexang 息壤平台
persona
Commits
e9d924cf
Commit
e9d924cf
authored
13 years ago
by
Lloyd Hilaiel
Browse files
Options
Downloads
Patches
Plain Diff
a script to migrate an sqlite database to mysql
parent
7897921c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/migrate_sqlite_to_mysql.js
+116
-0
116 additions, 0 deletions
scripts/migrate_sqlite_to_mysql.js
with
116 additions
and
0 deletions
scripts/migrate_sqlite_to_mysql.js
0 → 100755
+
116
−
0
View file @
e9d924cf
#!/usr/bin/env node
/* A lil' node.js script to perform a one time migration from sqlite to
* mysql */
const
mysql
=
require
(
'
mysql
'
),
path
=
require
(
'
path
'
),
sqlite
=
require
(
'
sqlite
'
);
const
schemas
=
[
"
CREATE TABLE user ( id INTEGER AUTO_INCREMENT PRIMARY KEY, passwd VARCHAR(64) );
"
,
"
CREATE TABLE email ( id INTEGER AUTO_INCREMENT PRIMARY KEY, user INTEGER, address VARCHAR(255) UNIQUE, INDEX(address) );
"
,
"
CREATE TABLE pubkey ( id INTEGER AUTO_INCREMENT PRIMARY KEY, email INTEGER, content TEXT, expiry DATETIME );
"
,
"
CREATE TABLE staged ( secret VARCHAR(48) PRIMARY KEY, new_acct BOOL, existing VARCHAR(255), email VARCHAR(255) UNIQUE, INDEX(email), pubkey TEXT, passwd VARCHAR(64), ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
"
];
// #1 open connection to mysql
client
=
new
mysql
.
Client
();
// mysql config requires
client
[
'
host
'
]
=
'
127.0.0.1
'
;
client
[
'
port
'
]
=
"
3306
"
;
client
[
'
user
'
]
=
"
browserid
"
;
client
[
'
password
'
]
=
""
;
function
fatal
(
err
)
{
console
.
log
(
"
ERROR:
"
,
err
.
toString
());
process
.
exit
(
1
);
}
client
.
connect
(
function
(
error
)
{
if
(
error
)
{
fatal
(
error
);
}
else
{
// now create the databse
client
.
useDatabase
(
"
browserid
"
,
function
(
err
)
{
if
(
err
)
fatal
(
err
);
function
createNextTable
(
i
)
{
if
(
i
<
schemas
.
length
)
{
client
.
query
(
schemas
[
i
],
function
(
err
)
{
if
(
err
)
{
fatal
(
err
);
}
else
{
createNextTable
(
i
+
1
);
}
});
}
else
{
onMysqlReady
();
}
}
createNextTable
(
0
);
});
}
});
var
sqlitedb
;
function
onMysqlReady
()
{
// now connect up to sqlite
sqlitedb
=
new
sqlite
.
Database
();
// a configurable parameter if set immediately after require() of db.js
var
dbPath
=
path
.
join
(
__dirname
,
"
authdb.sqlite
"
);
sqlitedb
.
open
(
dbPath
,
function
(
error
)
{
if
(
error
)
fatal
(
error
);
onSQLITEReady
();
});
}
function
getAllRows
(
table
,
start
,
gotRowCallback
)
{
var
sql
=
"
select * from
"
+
table
;
sqlitedb
.
query
(
sql
,
function
(
e
,
r
)
{
if
(
e
)
fatal
(
e
);
gotRowCallback
(
r
);
});
}
var
done
=
0
;
function
checkDone
()
{
if
(
done
++
==
2
)
{
client
.
end
(
function
()
{
console
.
log
(
"
all done!
"
);
process
.
exit
(
0
);
});
}
}
function
onSQLITEReady
()
{
console
.
log
(
"
getting all rows
"
);
getAllRows
(
"
users
"
,
0
,
function
(
row
)
{
if
(
row
)
{
client
.
query
(
'
INSERT INTO user (id, passwd) VALUES(?,?)
'
,
[
row
.
id
,
row
.
password
]);
}
else
{
checkDone
();
}
});
getAllRows
(
"
emails
"
,
0
,
function
(
row
)
{
if
(
row
)
{
client
.
query
(
'
INSERT INTO email (id, user, address) VALUES(?,?,?) ON DUPLICATE KEY UPDATE id=?
'
,
[
row
.
id
,
row
.
user
,
row
.
address
,
row
.
id
]);
}
else
{
checkDone
();
}
});
getAllRows
(
"
keys
"
,
0
,
function
(
row
)
{
if
(
row
)
{
client
.
query
(
'
INSERT INTO pubkey (id, email, content, expiry) VALUES(?,?,?,?)
'
,
[
row
.
id
,
row
.
email
,
row
.
key
,
row
.
expires
]);
}
else
{
checkDone
();
}
});
}
\ No newline at end of file
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