1
0
forked from MTSR/mapserver

sql file separation

This commit is contained in:
NatureFreshMilk 2019-02-13 15:28:51 +01:00
parent 3555e0b547
commit 2119b09f85
3 changed files with 34 additions and 36 deletions

View File

@ -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
}

View File

@ -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,

View File

@ -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
);