MariaDB: Add migrate test database and dialect_mysql_test.go #2398

This commit is contained in:
Michael Mayer 2022-06-16 01:27:14 +02:00
parent 78c12cabe0
commit 64e938b0d7
5 changed files with 1254 additions and 3 deletions

View file

@ -1,5 +1,5 @@
# Debian 12, Codename 'Bookworm'
FROM photoprism/develop:220613-bookworm
FROM photoprism/develop:220615-bookworm
## alternative base images
# FROM photoprism/develop:bullseye # Debian 11, Codename 'Bullseye'

View file

@ -107,7 +107,7 @@ services:
## Docs: https://mariadb.com/docs/reference/
mariadb:
image: mariadb:10.8
command: mysqld --port=4001 --innodb-buffer-pool-size=256M --transaction-isolation=READ-COMMITTED --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --max-connections=512 --innodb-rollback-on-timeout=OFF --innodb-lock-wait-timeout=120
command: mysqld --port=4001 --innodb-strict-mode=1 --innodb-buffer-pool-size=256M --transaction-isolation=READ-COMMITTED --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --max-connections=512 --innodb-rollback-on-timeout=OFF --innodb-lock-wait-timeout=120
expose:
- "4001"
ports:

View file

@ -0,0 +1,60 @@
package migrate
import (
"os/exec"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/sirupsen/logrus"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
func TestDialectMysql(t *testing.T) {
if dumpName, err := filepath.Abs("./testdata/migrate_mysql.sql"); err != nil {
t.Fatal(err)
} else if err = exec.Command("mysql", "-u", "migrate", "-pmigrate", "migrate",
"-e", "source "+dumpName).Run(); err != nil {
t.Fatal(err)
}
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
db, err := gorm.Open(
"mysql",
"migrate:migrate@tcp(mariadb:4001)/migrate?charset=utf8mb4,utf8&collation=utf8mb4_unicode_ci&parseTime=true",
)
if err != nil || db == nil {
if err != nil {
t.Fatal(err)
}
return
}
defer db.Close()
db.LogMode(false)
db.SetLogger(log)
if err = Auto(db, true, nil); err != nil {
t.Error(err)
}
stmt := db.Table("photos").Where("photo_description = '' OR photo_description IS NULL")
count := 0
// Fetch count from database.
if err = stmt.Count(&count).Error; err != nil {
t.Error(err)
} else {
assert.Equal(t, 0, count)
}
}

File diff suppressed because it is too large Load diff

View file

@ -29,6 +29,10 @@ CREATE DATABASE IF NOT EXISTS testdb;
CREATE USER IF NOT EXISTS testdb@'%' IDENTIFIED BY 'testdb';
GRANT ALL PRIVILEGES ON testdb.* TO testdb@'%';
CREATE DATABASE IF NOT EXISTS `migrate`;
CREATE USER IF NOT EXISTS 'migrate'@'%' IDENTIFIED BY 'migrate';
GRANT ALL PRIVILEGES ON `migrate`.* TO 'migrate'@'%';
CREATE DATABASE IF NOT EXISTS acceptance;
CREATE USER IF NOT EXISTS acceptance@'%' IDENTIFIED BY 'acceptance';
GRANT ALL PRIVILEGES ON acceptance.* TO acceptance@'%';
@ -49,9 +53,12 @@ CREATE DATABASE IF NOT EXISTS photoprism_05;
CREATE USER IF NOT EXISTS photoprism_05@'%' IDENTIFIED BY 'photoprism_05';
GRANT ALL PRIVILEGES ON photoprism_05.* TO photoprism_05@'%';
FLUSH PRIVILEGES;
-- ----------------------------------------------------------------------------------------
-- init "keycloak" db
-- ----------------------------------------------------------------------------------------
USE keycloak;
--