存档当前项目
This commit is contained in:
@@ -28,6 +28,11 @@ function loadRootEnv() {
|
||||
}
|
||||
}
|
||||
|
||||
function getMigrationVersion(file) {
|
||||
const match = file.match(/^(\d+)_/);
|
||||
return match ? match[1] : file;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
loadRootEnv();
|
||||
|
||||
@@ -50,9 +55,16 @@ async function main() {
|
||||
`);
|
||||
|
||||
for (const file of files) {
|
||||
const version = getMigrationVersion(file);
|
||||
const [rows] = await connection.query(
|
||||
'SELECT version FROM schema_migrations WHERE version = ?',
|
||||
[file],
|
||||
`
|
||||
SELECT version
|
||||
FROM schema_migrations
|
||||
WHERE version = ?
|
||||
OR version = ?
|
||||
OR version LIKE ?
|
||||
`,
|
||||
[version, file, `${version}\\_%`],
|
||||
);
|
||||
if (rows.length > 0) {
|
||||
console.log(`skip ${file}`);
|
||||
@@ -70,7 +82,7 @@ async function main() {
|
||||
}
|
||||
await connection.query(
|
||||
'INSERT INTO schema_migrations (version) VALUES (?)',
|
||||
[file],
|
||||
[version],
|
||||
);
|
||||
await connection.commit();
|
||||
console.log(`applied ${file}`);
|
||||
|
||||
Reference in New Issue
Block a user