wip fo sql files in vfs

This commit is contained in:
NatureFreshMilk 2019-02-13 14:47:32 +01:00
parent 504bc4f424
commit 3555e0b547
3 changed files with 14 additions and 16 deletions

View File

@ -1,20 +1,5 @@
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 = `
select pos,data,mtime
from blocks b

View File

@ -6,6 +6,7 @@ import (
"github.com/sirupsen/logrus"
"mapserver/coords"
"mapserver/db"
"mapserver/vfs"
"time"
)
@ -38,7 +39,7 @@ func (db *Sqlite3Accessor) Migrate() error {
if !hasMtime {
log.WithFields(logrus.Fields{"filename": db.filename}).Info("Migrating database")
start := time.Now()
_, err = rwdb.Exec(migrateScript)
_, err = rwdb.Exec(vfs.FSMustString(false, "/sql/sqlite_mapdb_migrate.sql"))
if err != nil {
return err
}

View 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;