Find and sort migration files
This commit is contained in:
parent
3e15c4b047
commit
6eb7d78c59
@ -1,5 +1,9 @@
|
|||||||
-- LaunchBrowser()
|
-- LaunchBrowser()
|
||||||
|
|
||||||
|
local migrate = require "migrate"
|
||||||
|
|
||||||
|
migrate.migrate()
|
||||||
|
|
||||||
fm = require "fullmoon"
|
fm = require "fullmoon"
|
||||||
fm.setTemplate("hello", "Hello, {%& name %}")
|
fm.setTemplate("hello", "Hello, {%& name %}")
|
||||||
fm.setRoute("/hello/:name", function(r)
|
fm.setRoute("/hello/:name", function(r)
|
||||||
|
35
assets/.lua/migrate.lua
Normal file
35
assets/.lua/migrate.lua
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
local re = require "re"
|
||||||
|
local path = require "path"
|
||||||
|
|
||||||
|
local filenameRegex = re.compile([=[^([0-9]+).*\.sql$]=])
|
||||||
|
|
||||||
|
local function migrate()
|
||||||
|
local migrations = {}
|
||||||
|
local seqnums = {}
|
||||||
|
local paths = GetZipPaths("/migrations/")
|
||||||
|
for _, p in ipairs(paths) do
|
||||||
|
-- basename -> sequence number
|
||||||
|
-- check that sequence number doesn't already exist
|
||||||
|
local basename = path.basename(p)
|
||||||
|
local _, seqnum = filenameRegex:search(basename)
|
||||||
|
seqnum = tonumber(seqnum)
|
||||||
|
if seqnum and not seqnums[seqnum] then
|
||||||
|
table.insert(seqnums, seqnum)
|
||||||
|
table.insert(migrations, {
|
||||||
|
filename = p,
|
||||||
|
seqnum = seqnum,
|
||||||
|
})
|
||||||
|
else
|
||||||
|
print(string.format("found weird migration name: %s", p))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
table.sort(migrations, function(a, b) return a.seqnum < b.seqnum end)
|
||||||
|
for i,mig in ipairs(migrations) do
|
||||||
|
print(string.format("%d: %s", i, mig.filename))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
migrate = migrate,
|
||||||
|
}
|
0
assets/migrations/01 create node.sql
Normal file
0
assets/migrations/01 create node.sql
Normal file
0
assets/migrations/2 create node_type.sql
Normal file
0
assets/migrations/2 create node_type.sql
Normal file
Loading…
Reference in New Issue
Block a user