mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Replace packr with go embed (#1751)
* Embed performer images * Embed schema migrations * Update dependencies * Embed UI * Remove remaining packr references
This commit is contained in:
16
vendor/github.com/golang-migrate/migrate/v4/database/sqlite3/README.md
generated
vendored
16
vendor/github.com/golang-migrate/migrate/v4/database/sqlite3/README.md
generated
vendored
@@ -0,0 +1,16 @@
|
||||
# sqlite3
|
||||
|
||||
`sqlite3://path/to/database?query`
|
||||
|
||||
Unlike other migrate database drivers, the sqlite3 driver will automatically wrap each migration in an implicit transaction by default. Migrations must not contain explicit `BEGIN` or `COMMIT` statements. This behavior may change in a future major release. (See below for a workaround.)
|
||||
|
||||
Refer to [upstream documentation](https://github.com/mattn/go-sqlite3/blob/master/README.md#connection-string) for a complete list of query parameters supported by the sqlite3 database driver. The auxiliary query parameters listed below may be supplied to tailor migrate behavior. All auxiliary query parameters are optional.
|
||||
|
||||
| URL Query | WithInstance Config | Description |
|
||||
|------------|---------------------|-------------|
|
||||
| `x-migrations-table` | `MigrationsTable` | Name of the migrations table. Defaults to `schema_migrations`. |
|
||||
| `x-no-tx-wrap` | `NoTxWrap` | Disable implicit transactions when `true`. Migrations may, and should, contain explicit `BEGIN` and `COMMIT` statements. |
|
||||
|
||||
## Notes
|
||||
|
||||
* Uses the `github.com/mattn/go-sqlite3` sqlite db driver (cgo)
|
||||
|
||||
51
vendor/github.com/golang-migrate/migrate/v4/database/sqlite3/sqlite3.go
generated
vendored
51
vendor/github.com/golang-migrate/migrate/v4/database/sqlite3/sqlite3.go
generated
vendored
@@ -3,9 +3,11 @@ package sqlite3
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"go.uber.org/atomic"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
nurl "net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/golang-migrate/migrate/v4"
|
||||
@@ -28,11 +30,12 @@ var (
|
||||
type Config struct {
|
||||
MigrationsTable string
|
||||
DatabaseName string
|
||||
NoTxWrap bool
|
||||
}
|
||||
|
||||
type Sqlite struct {
|
||||
db *sql.DB
|
||||
isLocked bool
|
||||
isLocked atomic.Bool
|
||||
|
||||
config *Config
|
||||
}
|
||||
@@ -100,13 +103,25 @@ func (m *Sqlite) Open(url string) (database.Driver, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
migrationsTable := purl.Query().Get("x-migrations-table")
|
||||
qv := purl.Query()
|
||||
|
||||
migrationsTable := qv.Get("x-migrations-table")
|
||||
if len(migrationsTable) == 0 {
|
||||
migrationsTable = DefaultMigrationsTable
|
||||
}
|
||||
|
||||
noTxWrap := false
|
||||
if v := qv.Get("x-no-tx-wrap"); v != "" {
|
||||
noTxWrap, err = strconv.ParseBool(v)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("x-no-tx-wrap: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
mx, err := WithInstance(db, &Config{
|
||||
DatabaseName: purl.Path,
|
||||
MigrationsTable: migrationsTable,
|
||||
NoTxWrap: noTxWrap,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -129,6 +144,7 @@ func (m *Sqlite) Drop() (err error) {
|
||||
err = multierror.Append(err, errClose)
|
||||
}
|
||||
}()
|
||||
|
||||
tableNames := make([]string, 0)
|
||||
for tables.Next() {
|
||||
var tableName string
|
||||
@@ -139,6 +155,10 @@ func (m *Sqlite) Drop() (err error) {
|
||||
tableNames = append(tableNames, tableName)
|
||||
}
|
||||
}
|
||||
if err := tables.Err(); err != nil {
|
||||
return &database.Error{OrigErr: err, Query: []byte(query)}
|
||||
}
|
||||
|
||||
if len(tableNames) > 0 {
|
||||
for _, t := range tableNames {
|
||||
query := "DROP TABLE " + t
|
||||
@@ -158,18 +178,16 @@ func (m *Sqlite) Drop() (err error) {
|
||||
}
|
||||
|
||||
func (m *Sqlite) Lock() error {
|
||||
if m.isLocked {
|
||||
if !m.isLocked.CAS(false, true) {
|
||||
return database.ErrLocked
|
||||
}
|
||||
m.isLocked = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Sqlite) Unlock() error {
|
||||
if !m.isLocked {
|
||||
return nil
|
||||
if !m.isLocked.CAS(true, false) {
|
||||
return database.ErrNotLocked
|
||||
}
|
||||
m.isLocked = false
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -180,6 +198,9 @@ func (m *Sqlite) Run(migration io.Reader) error {
|
||||
}
|
||||
query := string(migr[:])
|
||||
|
||||
if m.config.NoTxWrap {
|
||||
return m.executeQueryNoTx(query)
|
||||
}
|
||||
return m.executeQuery(query)
|
||||
}
|
||||
|
||||
@@ -200,6 +221,13 @@ func (m *Sqlite) executeQuery(query string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Sqlite) executeQueryNoTx(query string) error {
|
||||
if _, err := m.db.Exec(query); err != nil {
|
||||
return &database.Error{OrigErr: err, Query: []byte(query)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Sqlite) SetVersion(version int, dirty bool) error {
|
||||
tx, err := m.db.Begin()
|
||||
if err != nil {
|
||||
@@ -211,9 +239,12 @@ func (m *Sqlite) SetVersion(version int, dirty bool) error {
|
||||
return &database.Error{OrigErr: err, Query: []byte(query)}
|
||||
}
|
||||
|
||||
if version >= 0 {
|
||||
query := fmt.Sprintf(`INSERT INTO %s (version, dirty) VALUES (%d, '%t')`, m.config.MigrationsTable, version, dirty)
|
||||
if _, err := tx.Exec(query); err != nil {
|
||||
// Also re-write the schema version for nil dirty versions to prevent
|
||||
// empty schema version for failed down migration on the first migration
|
||||
// See: https://github.com/golang-migrate/migrate/issues/330
|
||||
if version >= 0 || (version == database.NilVersion && dirty) {
|
||||
query := fmt.Sprintf(`INSERT INTO %s (version, dirty) VALUES (?, ?)`, m.config.MigrationsTable)
|
||||
if _, err := tx.Exec(query, version, dirty); err != nil {
|
||||
if errRollback := tx.Rollback(); errRollback != nil {
|
||||
err = multierror.Append(err, errRollback)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user