From 1d8bb2d3adc7c44f54eb5597c4f4d7408a8a4814 Mon Sep 17 00:00:00 2001 From: sauls8t Date: Mon, 12 Nov 2018 20:25:30 +0000 Subject: [PATCH] Add experimental string to timestamp for backup/restore --- core/env/provider.go | 21 +++++++-------------- edition/storage/mysql.go | 9 +++++++++ edition/storage/postgresql.go | 9 +++++++++ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/core/env/provider.go b/core/env/provider.go index a264428f..ea669f40 100644 --- a/core/env/provider.go +++ b/core/env/provider.go @@ -59,20 +59,6 @@ type StoreProvider interface { // QueryMeta is how to extract version number, collation, character set from database provider. QueryMeta() string - // QueryStartLock locks database tables. - // QueryStartLock() string - - // QueryFinishLock unlocks database tables. - // QueryFinishLock() string - - // QueryInsertProcessID returns database specific query that will - // insert ID of this running process. - // QueryInsertProcessID() string - - // QueryInsertProcessID returns database specific query that will - // delete ID of this running process. - // QueryDeleteProcessID() string - // QueryRecordVersionUpgrade returns database specific insert statement // that records the database version number. QueryRecordVersionUpgrade(version int) string @@ -110,4 +96,11 @@ type StoreProvider interface { // VerfiyCharacterCollation checks to see if actual database // has correct character set and collation settings. VerfiyCharacterCollation(charset, collation string) (charOK bool, requirements string) + + // ConvertTimestamp returns SQL function to correctly convert + // ISO 8601 format (e.g. '2016-09-08T06:37:23Z') to SQL specific + // timestamp value (e.g. 2016-09-08 06:37:23). + // Must use ? for parameter placeholder character as DB layer + // will convert to database specific parameter placeholder character. + ConvertTimestamp() (statement string) } diff --git a/edition/storage/mysql.go b/edition/storage/mysql.go index 32120fa3..aa8c8cb8 100644 --- a/edition/storage/mysql.go +++ b/edition/storage/mysql.go @@ -339,6 +339,15 @@ func (p MySQLProvider) VerfiyCharacterCollation(charset, collation string) (char return true, "" } +// ConvertTimestamp returns SQL function to correctly convert +// ISO 8601 format (e.g. '2016-09-08T06:37:23Z') to SQL specific +// timestamp value (e.g. 2016-09-08 06:37:23). +// Must use ? for parameter placeholder character as DB layer +// will convert to database specific parameter placeholder character. +func (p MySQLProvider) ConvertTimestamp() (statement string) { + return `STR_TO_DATE(?,'%Y-%m-%d %H:%i:%s')` +} + // convertDatabaseVersion turns database version string as major,minor,patch numerics. func convertDatabaseVersion(v string) (ints []int, err error) { ints = []int{0, 0, 0} diff --git a/edition/storage/postgresql.go b/edition/storage/postgresql.go index 02e97760..49eed41d 100644 --- a/edition/storage/postgresql.go +++ b/edition/storage/postgresql.go @@ -280,3 +280,12 @@ func (p PostgreSQLProvider) VerfiyCharacterCollation(charset, collation string) return true, "" } + +// ConvertTimestamp returns SQL function to correctly convert +// ISO 8601 format (e.g. '2016-09-08T06:37:23Z') to SQL specific +// timestamp value (e.g. 2016-09-08 06:37:23). +// Must use ? for parameter placeholder character as DB layer +// will convert to database specific parameter placeholder character. +func (p PostgreSQLProvider) ConvertTimestamp() (statement string) { + return `to_timestamp(?,'YYYY-MM-DD HH24:MI:SS')` +}