MariaDB: Add migrate test database and dialect_mysql_test.go #2398
This commit is contained in:
parent
78c12cabe0
commit
64e938b0d7
5 changed files with 1254 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
||||||
# Debian 12, Codename 'Bookworm'
|
# Debian 12, Codename 'Bookworm'
|
||||||
FROM photoprism/develop:220613-bookworm
|
FROM photoprism/develop:220615-bookworm
|
||||||
|
|
||||||
## alternative base images
|
## alternative base images
|
||||||
# FROM photoprism/develop:bullseye # Debian 11, Codename 'Bullseye'
|
# FROM photoprism/develop:bullseye # Debian 11, Codename 'Bullseye'
|
||||||
|
|
|
@ -107,7 +107,7 @@ services:
|
||||||
## Docs: https://mariadb.com/docs/reference/
|
## Docs: https://mariadb.com/docs/reference/
|
||||||
mariadb:
|
mariadb:
|
||||||
image: mariadb:10.8
|
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:
|
expose:
|
||||||
- "4001"
|
- "4001"
|
||||||
ports:
|
ports:
|
||||||
|
|
60
internal/migrate/dialect_mysql_test.go
Normal file
60
internal/migrate/dialect_mysql_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
1184
internal/migrate/testdata/migrate_mysql.sql
vendored
Normal file
1184
internal/migrate/testdata/migrate_mysql.sql
vendored
Normal file
File diff suppressed because it is too large
Load diff
|
@ -29,6 +29,10 @@ CREATE DATABASE IF NOT EXISTS testdb;
|
||||||
CREATE USER IF NOT EXISTS testdb@'%' IDENTIFIED BY 'testdb';
|
CREATE USER IF NOT EXISTS testdb@'%' IDENTIFIED BY 'testdb';
|
||||||
GRANT ALL PRIVILEGES ON testdb.* TO 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 DATABASE IF NOT EXISTS acceptance;
|
||||||
CREATE USER IF NOT EXISTS acceptance@'%' IDENTIFIED BY 'acceptance';
|
CREATE USER IF NOT EXISTS acceptance@'%' IDENTIFIED BY 'acceptance';
|
||||||
GRANT ALL PRIVILEGES ON acceptance.* TO 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';
|
CREATE USER IF NOT EXISTS photoprism_05@'%' IDENTIFIED BY 'photoprism_05';
|
||||||
GRANT ALL PRIVILEGES ON photoprism_05.* TO photoprism_05@'%';
|
GRANT ALL PRIVILEGES ON photoprism_05.* TO photoprism_05@'%';
|
||||||
|
|
||||||
|
|
||||||
FLUSH PRIVILEGES;
|
FLUSH PRIVILEGES;
|
||||||
|
|
||||||
|
-- ----------------------------------------------------------------------------------------
|
||||||
|
-- init "keycloak" db
|
||||||
|
-- ----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
USE keycloak;
|
USE keycloak;
|
||||||
|
|
||||||
--
|
--
|
||||||
|
|
Loading…
Reference in a new issue