forked from MTSR/mapserver
sql file separation
This commit is contained in:
parent
3555e0b547
commit
2119b09f85
@ -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
|
||||
}
|
||||
|
@ -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,
|
||||
|
32
server/static/sql/sqlite_mapobjectdb_migrate.sql
Normal file
32
server/static/sql/sqlite_mapobjectdb_migrate.sql
Normal 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
|
||||
);
|
Loading…
Reference in New Issue
Block a user