postgres stub

This commit is contained in:
NatureFreshMilk 2019-02-14 09:02:46 +01:00
parent c80a9140e9
commit 52b29dbd47
4 changed files with 33 additions and 27 deletions

View File

@ -0,0 +1,13 @@
package postgres
import (
"mapserver/settings"
"mapserver/layer"
"mapserver/db"
)
func (this *PostgresAccessor) FindNextInitialBlocks(s settings.Settings, layers []*layer.Layer, limit int) (*db.InitialBlocksResult, error) {
return nil, nil
}

View File

@ -3,9 +3,8 @@ package postgres
import ( import (
"database/sql" "database/sql"
"mapserver/coords" "mapserver/coords"
"mapserver/settings"
"mapserver/layer"
"mapserver/db" "mapserver/db"
"mapserver/vfs"
"time" "time"
_ "github.com/lib/pq" _ "github.com/lib/pq"
@ -26,7 +25,7 @@ func (db *PostgresAccessor) Migrate() error {
if !hasMtime { if !hasMtime {
log.Info("Migrating database") log.Info("Migrating database")
start := time.Now() start := time.Now()
_, err = db.db.Exec(migrateScript) _, err = db.db.Exec(vfs.FSMustString(false, "/sql/postgres_mapdb_migrate.sql"))
if err != nil { if err != nil {
return err return err
} }
@ -70,10 +69,6 @@ func (this *PostgresAccessor) FindBlocksByMtime(gtmtime int64, limit int) ([]*db
return blocks, nil return blocks, nil
} }
func (this *PostgresAccessor) FindNextInitialBlocks(s settings.Settings, layers []*layer.Layer, limit int) (*db.InitialBlocksResult, error) {
return nil, nil
}
func (this *PostgresAccessor) CountBlocks(frommtime, tomtime int64) (int, error) { func (this *PostgresAccessor) CountBlocks(frommtime, tomtime int64) (int, error) {
rows, err := this.db.Query(countBlocksQuery, frommtime, tomtime) rows, err := this.db.Query(countBlocksQuery, frommtime, tomtime)
if err != nil { if err != nil {

View File

@ -1,25 +1,5 @@
package postgres package postgres
const migrateScript = `
alter table blocks add column mtime bigint not null default 0;
create index BLOCKS_TIME on blocks(mtime);
create or replace function on_blocks_change() returns trigger as
$BODY$
BEGIN
NEW.mtime = floor(EXTRACT(EPOCH from now()) * 1000);
return NEW;
END;
$BODY$
LANGUAGE plpgsql;
create trigger blocks_update
before insert or update
on blocks
for each row
execute procedure on_blocks_change();
`
const getBlocksByMtimeQuery = ` const getBlocksByMtimeQuery = `
select posx,posy,posz,data,mtime select posx,posy,posz,data,mtime

View File

@ -0,0 +1,18 @@
alter table blocks add column mtime bigint not null default 0;
create index BLOCKS_TIME on blocks(mtime);
create or replace function on_blocks_change() returns trigger as
$BODY$
BEGIN
NEW.mtime = floor(EXTRACT(EPOCH from now()) * 1000);
return NEW;
END;
$BODY$
LANGUAGE plpgsql;
create trigger blocks_update
before insert or update
on blocks
for each row
execute procedure on_blocks_change();