Skip to content

Commit 7e8974f

Browse files
committed
MySQL 8: Improve migrate command, ignore errors when dropping indexes
1 parent 86c4315 commit 7e8974f

19 files changed

+369
-145
lines changed

docker-compose.ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ services:
3838
PHOTOPRISM_DATABASE_PASSWORD: "photoprism"
3939
PHOTOPRISM_TEST_DRIVER: "sqlite"
4040
PHOTOPRISM_TEST_DSN: ".test.db"
41+
PHOTOPRISM_TEST_DSN_MYSQL8: "root:photoprism@tcp(mysql:4001)/photoprism?charset=utf8mb4,utf8&collation=utf8mb4_unicode_ci&parseTime=true"
4142
PHOTOPRISM_ADMIN_PASSWORD: "photoprism" # The initial admin password (min 4 characters)
4243
PHOTOPRISM_ASSETS_PATH: "/go/src/github.com/photoprism/photoprism/assets"
4344
PHOTOPRISM_STORAGE_PATH: "/go/src/github.com/photoprism/photoprism/storage"
@@ -157,6 +158,21 @@ services:
157158
MYSQL_PASSWORD: photoprism
158159
MYSQL_DATABASE: photoprism
159160

161+
## MySQL Database Server
162+
## Docs: https://dev.mysql.com/doc/refman/8.0/en/
163+
mysql:
164+
image: mysql:8
165+
command: mysqld --port=4001 --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
166+
expose:
167+
- "4001" # Database port (internal)
168+
volumes:
169+
- "./scripts/sql/init-test-databases.sql:/docker-entrypoint-initdb.d/init-test-databases.sql"
170+
environment:
171+
MYSQL_ROOT_PASSWORD: photoprism
172+
MYSQL_USER: photoprism
173+
MYSQL_PASSWORD: photoprism
174+
MYSQL_DATABASE: photoprism
175+
160176
## Dummy WebDAV Server
161177
dummy-webdav:
162178
image: photoprism/dummy-webdav:20211109

docker-compose.db.yml renamed to docker-compose.mariadb.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,6 @@ services:
5757
MYSQL_PASSWORD: photoprism
5858
MYSQL_DATABASE: photoprism
5959

60-
mysql-8:
61-
image: mysql:8
62-
command: mysqld --port=4001 --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
63-
expose:
64-
- "4001" # Database port (internal)
65-
volumes:
66-
- "./scripts/sql/init-test-databases.sql:/docker-entrypoint-initdb.d/init-test-databases.sql"
67-
environment:
68-
MYSQL_ROOT_PASSWORD: photoprism
69-
MYSQL_USER: photoprism
70-
MYSQL_PASSWORD: photoprism
71-
MYSQL_DATABASE: photoprism
72-
7360
networks:
7461
default:
7562
external:

docker-compose.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ services:
2222
- "2343:2343" # Acceptance Test HTTP port (host:container)
2323
shm_size: "2gb"
2424
environment:
25+
PHOTOPRISM_ADMIN_PASSWORD: "photoprism" # The initial admin password (min 4 characters)
2526
PHOTOPRISM_UID: ${UID:-1000}
2627
PHOTOPRISM_GID: ${GID:-1000}
2728
PHOTOPRISM_SITE_URL: "http://localhost:2342/"
@@ -44,7 +45,7 @@ services:
4445
PHOTOPRISM_DATABASE_PASSWORD: "photoprism"
4546
PHOTOPRISM_TEST_DRIVER: "sqlite"
4647
PHOTOPRISM_TEST_DSN: ".test.db"
47-
PHOTOPRISM_ADMIN_PASSWORD: "photoprism" # The initial admin password (min 4 characters)
48+
PHOTOPRISM_TEST_DSN_MYSQL8: "root:photoprism@tcp(mysql:4001)/photoprism?charset=utf8mb4,utf8&collation=utf8mb4_unicode_ci&parseTime=true"
4849
PHOTOPRISM_ASSETS_PATH: "/go/src/github.com/photoprism/photoprism/assets"
4950
PHOTOPRISM_STORAGE_PATH: "/go/src/github.com/photoprism/photoprism/storage"
5051
PHOTOPRISM_ORIGINALS_PATH: "/go/src/github.com/photoprism/photoprism/storage/originals"
@@ -103,6 +104,21 @@ services:
103104
MYSQL_PASSWORD: photoprism
104105
MYSQL_DATABASE: photoprism
105106

107+
## MySQL Database Server
108+
## Docs: https://dev.mysql.com/doc/refman/8.0/en/
109+
mysql:
110+
image: mysql:8
111+
command: mysqld --port=4001 --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
112+
expose:
113+
- "4001" # Database port (internal)
114+
volumes:
115+
- "./scripts/sql/init-test-databases.sql:/docker-entrypoint-initdb.d/init-test-databases.sql"
116+
environment:
117+
MYSQL_ROOT_PASSWORD: photoprism
118+
MYSQL_USER: photoprism
119+
MYSQL_PASSWORD: photoprism
120+
MYSQL_DATABASE: photoprism
121+
106122
## Dummy WebDAV Server
107123
dummy-webdav:
108124
image: photoprism/dummy-webdav:20211109

internal/commands/migrate.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,26 @@ import (
44
"context"
55
"time"
66

7+
"github.com/sirupsen/logrus"
78
"github.com/urfave/cli"
89

910
"github.com/photoprism/photoprism/internal/config"
1011
)
1112

12-
// MigrateCommand registers the migrate cli command.
13+
// MigrateCommand registers the "migrate" CLI command.
1314
var MigrateCommand = cli.Command{
14-
Name: "migrate",
15-
Usage: "Updates the index database schema",
15+
Name: "migrate",
16+
Usage: "Updates the index database schema",
17+
Flags: []cli.Flag{
18+
cli.BoolFlag{
19+
Name: "failed, f",
20+
Usage: "run previously failed migrations",
21+
},
22+
cli.BoolFlag{
23+
Name: "trace, t",
24+
Usage: "show trace logs for debugging",
25+
},
26+
},
1627
Action: migrateAction,
1728
}
1829

@@ -29,15 +40,26 @@ func migrateAction(ctx *cli.Context) error {
2940
return err
3041
}
3142

43+
defer conf.Shutdown()
44+
45+
if ctx.Bool("trace") {
46+
log.SetLevel(logrus.TraceLevel)
47+
log.Infoln("migrate: enabled trace mode")
48+
}
49+
50+
runFailed := ctx.Bool("failed")
51+
52+
if runFailed {
53+
log.Infoln("migrate: running previously failed migrations")
54+
}
55+
3256
log.Infoln("migrating database schema...")
3357

34-
conf.InitDb()
58+
conf.MigrateDb(runFailed)
3559

3660
elapsed := time.Since(start)
3761

3862
log.Infof("migration completed in %s", elapsed)
3963

40-
conf.Shutdown()
41-
4264
return nil
4365
}

internal/commands/places.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@ import (
1616
// PlacesCommand registers the places subcommands.
1717
var PlacesCommand = cli.Command{
1818
Name: "places",
19-
Usage: "Geographic data subcommands",
19+
Usage: "Maps and location details subcommands",
2020
Subcommands: []cli.Command{
2121
{
22-
Name: "update",
23-
Usage: "Retrieves updated location details",
22+
Name: "update",
23+
Usage: "Retrieves updated location details",
24+
Flags: []cli.Flag{
25+
cli.BoolFlag{
26+
Name: "yes, y",
27+
Hidden: true,
28+
Usage: "assume \"yes\" as answer to all prompts and run non-interactively",
29+
},
30+
},
2431
Action: placesUpdateAction,
2532
},
2633
},
@@ -46,14 +53,16 @@ func placesUpdateAction(ctx *cli.Context) error {
4653
return nil
4754
}
4855

49-
confirmPrompt := promptui.Prompt{
50-
Label: "Interrupting the update may result in inconsistent location details. Proceed?",
51-
IsConfirm: true,
52-
}
56+
if !ctx.Bool("yes") {
57+
confirmPrompt := promptui.Prompt{
58+
Label: "Interrupting the update may result in inconsistent location details. Proceed?",
59+
IsConfirm: true,
60+
}
5361

54-
// Abort?
55-
if _, err := confirmPrompt.Run(); err != nil {
56-
return nil
62+
// Abort?
63+
if _, err := confirmPrompt.Run(); err != nil {
64+
return nil
65+
}
5766
}
5867

5968
start := time.Now()

0 commit comments

Comments
 (0)