mirror of
https://github.com/go-shiori/shiori.git
synced 2025-01-15 20:37:44 +08:00
Make migrations transparent to the user (#530)
* refactor: remove migrate command * reafactor: avoid migration errors on no changes
This commit is contained in:
parent
54fc9399b3
commit
3fcb295d72
6 changed files with 22 additions and 35 deletions
|
@ -4,8 +4,7 @@ Before using `shiori`, make sure it has been installed on your system. By defaul
|
|||
|
||||
- [Running Docker Container](#running-docker-container)
|
||||
- [Using Command Line Interface](#using-command-line-interface)
|
||||
- [Search syntax](#search-syntax)
|
||||
- [Running migrations](#running-migrations)
|
||||
- [Search syntax](#search-syntax)
|
||||
- [Using Web Interface](#using-web-interface)
|
||||
- [Improved import from Pocket](#improved-import-from-pocket)
|
||||
- [Import from Wallabag](#import-from-wallabag)
|
||||
|
@ -43,14 +42,6 @@ Now you can use `shiori` like normal. If you've finished, you can stop and remov
|
|||
docker stop shiori
|
||||
```
|
||||
|
||||
## Running migrations
|
||||
|
||||
If this is a fresh install or you're upgrading versions, you'll need to migrate the database to apply any required
|
||||
changes for Shiori to work properly:
|
||||
|
||||
- If you're using the binary version: `shiori migrate`
|
||||
- If you're running the containerized version: `docker run --rm -v $(pwd):/shiori ghcr.io/go-shiori/shiori migrate` (you can also start a shell on the running container and perform the migration there).
|
||||
|
||||
## Using Command Line Interface
|
||||
|
||||
Shiori is composed by several subcommands. To see the documentation, run `shiori -h` :
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func migrateCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "migrate",
|
||||
Short: "Migrates the database to the latest version",
|
||||
Run: migrateHandler,
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func migrateHandler(cmd *cobra.Command, args []string) {
|
||||
if err := db.Migrate(); err != nil {
|
||||
cError.Printf("Error during migration: %s", err)
|
||||
}
|
||||
}
|
|
@ -38,7 +38,6 @@ func ShioriCmd() *cobra.Command {
|
|||
pocketCmd(),
|
||||
serveCmd(),
|
||||
checkCmd(),
|
||||
migrateCmd(),
|
||||
)
|
||||
|
||||
return rootCmd
|
||||
|
@ -68,6 +67,12 @@ func preRunRootHandler(cmd *cobra.Command, args []string) {
|
|||
cError.Printf("Failed to open database: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Migrate
|
||||
if err := db.Migrate(); err != nil {
|
||||
cError.Printf("Error running migration: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func getDataDir(portableMode bool) (string, error) {
|
||||
|
|
|
@ -58,7 +58,11 @@ func (db *MySQLDatabase) Migrate() error {
|
|||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return migration.Up()
|
||||
if err := migration.Up(); err != nil && !errors.Is(err, migrate.ErrNoChange) {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SaveBookmarks saves new or updated bookmarks to database.
|
||||
|
|
|
@ -59,7 +59,11 @@ func (db *PGDatabase) Migrate() error {
|
|||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return migration.Up()
|
||||
if err := migration.Up(); err != nil && !errors.Is(err, migrate.ErrNoChange) {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SaveBookmarks saves new or updated bookmarks to database.
|
||||
|
|
|
@ -67,7 +67,11 @@ func (db *SQLiteDatabase) Migrate() error {
|
|||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return migration.Up()
|
||||
if err := migration.Up(); err != nil && !errors.Is(err, migrate.ErrNoChange) {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SaveBookmarks saves new or updated bookmarks to database.
|
||||
|
|
Loading…
Reference in a new issue