wip fo sql files in vfs
This commit is contained in:
parent
504bc4f424
commit
3555e0b547
@ -1,20 +1,5 @@
|
|||||||
package sqlite
|
package sqlite
|
||||||
|
|
||||||
const migrateScript = `
|
|
||||||
alter table blocks add mtime integer default 0;
|
|
||||||
create index blocks_mtime on blocks(mtime);
|
|
||||||
|
|
||||||
CREATE TRIGGER update_blocks_mtime_insert after insert on blocks for each row
|
|
||||||
begin
|
|
||||||
update blocks set mtime = strftime('%s', 'now') where pos = new.pos;
|
|
||||||
end;
|
|
||||||
|
|
||||||
CREATE TRIGGER update_blocks_mtime_update after update on blocks for each row
|
|
||||||
begin
|
|
||||||
update blocks set mtime = strftime('%s', 'now') where pos = old.pos;
|
|
||||||
end;
|
|
||||||
`
|
|
||||||
|
|
||||||
const getBlocksByMtimeQuery = `
|
const getBlocksByMtimeQuery = `
|
||||||
select pos,data,mtime
|
select pos,data,mtime
|
||||||
from blocks b
|
from blocks b
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"mapserver/coords"
|
"mapserver/coords"
|
||||||
"mapserver/db"
|
"mapserver/db"
|
||||||
|
"mapserver/vfs"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ func (db *Sqlite3Accessor) Migrate() error {
|
|||||||
if !hasMtime {
|
if !hasMtime {
|
||||||
log.WithFields(logrus.Fields{"filename": db.filename}).Info("Migrating database")
|
log.WithFields(logrus.Fields{"filename": db.filename}).Info("Migrating database")
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
_, err = rwdb.Exec(migrateScript)
|
_, err = rwdb.Exec(vfs.FSMustString(false, "/sql/sqlite_mapdb_migrate.sql"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
12
server/static/sql/sqlite_mapdb_migrate.sql
Normal file
12
server/static/sql/sqlite_mapdb_migrate.sql
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
alter table blocks add mtime integer default 0;
|
||||||
|
create index blocks_mtime on blocks(mtime);
|
||||||
|
|
||||||
|
CREATE TRIGGER update_blocks_mtime_insert after insert on blocks for each row
|
||||||
|
begin
|
||||||
|
update blocks set mtime = strftime('%s', 'now') where pos = new.pos;
|
||||||
|
end;
|
||||||
|
|
||||||
|
CREATE TRIGGER update_blocks_mtime_update after update on blocks for each row
|
||||||
|
begin
|
||||||
|
update blocks set mtime = strftime('%s', 'now') where pos = old.pos;
|
||||||
|
end;
|
Loading…
Reference in New Issue
Block a user