diff --git a/server/mapobjectdb/sqlite/migrate.go b/server/mapobjectdb/sqlite/migrate.go index 1ebc9f9..fc3576b 100644 --- a/server/mapobjectdb/sqlite/migrate.go +++ b/server/mapobjectdb/sqlite/migrate.go @@ -4,6 +4,7 @@ import ( "database/sql" _ "github.com/mattn/go-sqlite3" "github.com/sirupsen/logrus" + "mapserver/vfs" "time" ) @@ -15,7 +16,7 @@ type Sqlite3Accessor struct { func (db *Sqlite3Accessor) Migrate() error { log.WithFields(logrus.Fields{"filename": db.filename}).Info("Migrating database") start := time.Now() - _, err := db.db.Exec(migrateScript) + _, err := db.db.Exec(vfs.FSMustString(false, "/sql/sqlite_mapobjectdb_migrate.sql")) if err != nil { return err } diff --git a/server/mapobjectdb/sqlite/sql.go b/server/mapobjectdb/sqlite/sql.go index dd8a991..c84a39c 100644 --- a/server/mapobjectdb/sqlite/sql.go +++ b/server/mapobjectdb/sqlite/sql.go @@ -1,40 +1,5 @@ package sqlite -const migrateScript = ` -PRAGMA foreign_keys = ON; -PRAGMA journal_mode = MEMORY; -PRAGMA synchronous = OFF; --TODO: this is just ridiculously slow otherwise... - -create table if not exists objects( - id integer primary key autoincrement, - x int, - y int, - z int, - posx int, - posy int, - posz int, - type varchar, - mtime bigint -); - -create index if not exists objects_pos on objects(posx,posy,posz); -create index if not exists objects_pos_type on objects(posx,posy,posz,type); - -create table if not exists object_attributes( - objectid integer not null, - key varchar not null, - value varchar not null, - FOREIGN KEY (objectid) references objects(id) ON DELETE CASCADE - primary key(objectid, key) -); - -create index if not exists object_attributes_key_value on object_attributes(key, value); - -create table if not exists settings( - key varchar primary key not null, - value varchar not null -); -` const getMapDataPosQuery = ` select o.id, o.type, o.mtime, diff --git a/server/static/sql/sqlite_mapobjectdb_migrate.sql b/server/static/sql/sqlite_mapobjectdb_migrate.sql new file mode 100644 index 0000000..74907a3 --- /dev/null +++ b/server/static/sql/sqlite_mapobjectdb_migrate.sql @@ -0,0 +1,32 @@ +PRAGMA foreign_keys = ON; +PRAGMA journal_mode = MEMORY; + +create table if not exists objects( + id integer primary key autoincrement, + x int, + y int, + z int, + posx int, + posy int, + posz int, + type varchar, + mtime bigint +); + +create index if not exists objects_pos on objects(posx,posy,posz); +create index if not exists objects_pos_type on objects(posx,posy,posz,type); + +create table if not exists object_attributes( + objectid integer not null, + key varchar not null, + value varchar not null, + FOREIGN KEY (objectid) references objects(id) ON DELETE CASCADE + primary key(objectid, key) +); + +create index if not exists object_attributes_key_value on object_attributes(key, value); + +create table if not exists settings( + key varchar primary key not null, + value varchar not null +);