diff options
author | zeripath <art27@cantab.net> | 2019-12-10 07:49:05 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-10 07:49:05 +0000 |
commit | d3a9c4ceec85489bf917eba8b45fa57fd0c1f4e6 (patch) | |
tree | 92cc81b80f67854d49f347f6187fbf3006cb6ba1 /models | |
parent | 2d8a89563d3cc9be4564c927d2df2317ce758ef8 (diff) | |
download | gitea-d3a9c4ceec85489bf917eba8b45fa57fd0c1f4e6.tar.gz gitea-d3a9c4ceec85489bf917eba8b45fa57fd0c1f4e6.zip |
Testing: Update postgres sequences (#9304)
Diffstat (limited to 'models')
-rw-r--r-- | models/test_fixtures.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/models/test_fixtures.go b/models/test_fixtures.go index 8ef9e1af90..fe6a790b0d 100644 --- a/models/test_fixtures.go +++ b/models/test_fixtures.go @@ -35,5 +35,37 @@ func LoadFixtures() error { if err != nil { fmt.Printf("LoadFixtures failed after retries: %v\n", err) } + // Now if we're running postgres we need to tell it to update the sequences + if x.Dialect().DriverName() == "postgres" { + results, err := x.QueryString(`SELECT 'SELECT SETVAL(' || + quote_literal(quote_ident(PGT.schemaname) || '.' || quote_ident(S.relname)) || + ', COALESCE(MAX(' ||quote_ident(C.attname)|| '), 1) ) FROM ' || + quote_ident(PGT.schemaname)|| '.'||quote_ident(T.relname)|| ';' + FROM pg_class AS S, + pg_depend AS D, + pg_class AS T, + pg_attribute AS C, + pg_tables AS PGT + WHERE S.relkind = 'S' + AND S.oid = D.objid + AND D.refobjid = T.oid + AND D.refobjid = C.attrelid + AND D.refobjsubid = C.attnum + AND T.relname = PGT.tablename + ORDER BY S.relname;`) + if err != nil { + fmt.Printf("Failed to generate sequence update: %v\n", err) + return err + } + for _, r := range results { + for _, value := range r { + _, err = x.Exec(value) + if err != nil { + fmt.Printf("Failed to update sequence: %s Error: %v\n", value, err) + return err + } + } + } + } return err } |