From 2cb694f53421588b26d707a2d3d89f7c37abae55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Thu, 31 Aug 2023 13:51:35 +0200 Subject: [PATCH] Added Publisher.Version to enable comparisons in applications using this library --- database.go | 6 +++--- upgrader.go | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/database.go b/database.go index 18b3856..cd3eb52 100644 --- a/database.go +++ b/database.go @@ -19,11 +19,11 @@ func newDatabase(host string, port int, dbName, user, pass string) (dbase Databa func (dbase Database) sqlConnString() string {// {{{ return fmt.Sprintf( - "postgresql://%s:%s@%s:%d/%s?sslmode=disable", - dbase.Username, - dbase.Password, + "host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", dbase.Host, dbase.Port, + dbase.Username, + dbase.Password, dbase.DbName, ) }// }}} diff --git a/upgrader.go b/upgrader.go index 820aa3f..7cb65f2 100644 --- a/upgrader.go +++ b/upgrader.go @@ -28,6 +28,17 @@ func (upgrader *Upgrader) SetLogCallback(callback func(string, string)) {// {{{ func (upgrader *Upgrader) SetSqlCallback(callback func(string, int) ([]byte, bool)) {// {{{ upgrader.sqlCallback = callback }// }}} +// Version returns the current dbschema version for the given database name. +func (upgrader *Upgrader) Version(dbName string) (version int, err error) {// {{{ + dbase, found := upgrader.databases[dbName] + if !found { + err = fmt.Errorf("Database %s not previously added to the upgrader", dbName) + return + } + + version, err = dbase.version() + return +}// }}} func (dbase Database) createSchemaTable() (err error) {// {{{ dbase.upgrader.logCallback("create", fmt.Sprintf("%s, _db.schema", dbase.DbName))