mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Rebuild association tables, ensure file-system-based galleries cannot be changed (#2955)
* Re-create tables to include primary keys * Filesystem-based galleries cannot change images
This commit is contained in:
@@ -21,6 +21,11 @@ type dbReader interface {
|
||||
QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
|
||||
}
|
||||
|
||||
type stmt struct {
|
||||
*sql.Stmt
|
||||
query string
|
||||
}
|
||||
|
||||
func logSQL(start time.Time, query string, args ...interface{}) {
|
||||
since := time.Since(start)
|
||||
if since >= slowLogTime {
|
||||
@@ -117,3 +122,35 @@ func (*dbWrapper) Exec(ctx context.Context, query string, args ...interface{}) (
|
||||
|
||||
return ret, sqlError(err, query, args...)
|
||||
}
|
||||
|
||||
// Prepare creates a prepared statement.
|
||||
func (*dbWrapper) Prepare(ctx context.Context, query string, args ...interface{}) (*stmt, error) {
|
||||
tx, err := getTx(ctx)
|
||||
if err != nil {
|
||||
return nil, sqlError(err, query, args...)
|
||||
}
|
||||
|
||||
// nolint:sqlclosecheck
|
||||
ret, err := tx.PrepareContext(ctx, query)
|
||||
if err != nil {
|
||||
return nil, sqlError(err, query, args...)
|
||||
}
|
||||
|
||||
return &stmt{
|
||||
query: query,
|
||||
Stmt: ret,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (*dbWrapper) ExecStmt(ctx context.Context, stmt *stmt, args ...interface{}) (sql.Result, error) {
|
||||
_, err := getTx(ctx)
|
||||
if err != nil {
|
||||
return nil, sqlError(err, stmt.query, args...)
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
ret, err := stmt.ExecContext(ctx, args...)
|
||||
logSQL(start, stmt.query, args...)
|
||||
|
||||
return ret, sqlError(err, stmt.query, args...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user