1
0
Fork 0
forked from forgejo/forgejo

go-sqlite3 gomod version (#12490)

This commit is contained in:
techknowlogick 2020-08-13 21:54:46 -04:00 committed by GitHub
parent b37c7dd384
commit 8a0049bb03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 13260 additions and 7349 deletions

View file

@ -109,7 +109,7 @@ func Dialect(dialect string) func(*Loader) error {
func helperForDialect(dialect string) (helper, error) {
switch dialect {
case "postgres", "postgresql", "timescaledb":
case "postgres", "postgresql", "timescaledb", "pgx":
return &postgreSQL{}, nil
case "mysql", "mariadb":
return &mySQL{}, nil
@ -139,6 +139,22 @@ func UseAlterConstraint() func(*Loader) error {
}
}
// UseDropConstraint If true, the constraints will be dropped
// and recreated after loading fixtures. This is implemented mainly to support
// CockroachDB which does not support other methods.
// Only valid for PostgreSQL dialect. Returns an error otherwise.
func UseDropConstraint() func(*Loader) error {
return func(l *Loader) error {
pgHelper, ok := l.helper.(*postgreSQL)
if !ok {
return fmt.Errorf("testfixtures: UseDropConstraint is only valid for PostgreSQL databases")
}
pgHelper.useDropConstraint = true
return nil
}
}
// SkipResetSequences prevents Loader from reseting sequences after loading
// fixtures.
//
@ -324,19 +340,34 @@ func (l *Loader) Load() error {
}
err := l.helper.disableReferentialIntegrity(l.db, func(tx *sql.Tx) error {
modifiedTables := make(map[string]bool, len(l.fixturesFiles))
for _, file := range l.fixturesFiles {
modified, err := l.helper.isTableModified(tx, file.fileNameWithoutExtension())
tableName := file.fileNameWithoutExtension()
modified, err := l.helper.isTableModified(tx, tableName)
if err != nil {
return err
}
modifiedTables[tableName] = modified
}
// Delete existing table data for specified fixtures before populating the data. This helps avoid
// DELETE CASCADE constraints when using the `UseAlterConstraint()` option.
for _, file := range l.fixturesFiles {
modified := modifiedTables[file.fileNameWithoutExtension()]
if !modified {
continue
}
if err := file.delete(tx, l.helper); err != nil {
return err
}
}
err = l.helper.whileInsertOnTable(tx, file.fileNameWithoutExtension(), func() error {
for _, file := range l.fixturesFiles {
modified := modifiedTables[file.fileNameWithoutExtension()]
if !modified {
continue
}
err := l.helper.whileInsertOnTable(tx, file.fileNameWithoutExtension(), func() error {
for j, i := range file.insertSQLs {
if _, err := tx.Exec(i.sql, i.params...); err != nil {
return &InsertError{