File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -35,5 +35,37 @@ func LoadFixtures() error {
3535 if err != nil {
3636 fmt .Printf ("LoadFixtures failed after retries: %v\n " , err )
3737 }
38+ // Now if we're running postgres we need to tell it to update the sequences
39+ if x .Dialect ().DriverName () == "postgres" {
40+ results , err := x .QueryString (`SELECT 'SELECT SETVAL(' ||
41+ quote_literal(quote_ident(PGT.schemaname) || '.' || quote_ident(S.relname)) ||
42+ ', COALESCE(MAX(' ||quote_ident(C.attname)|| '), 1) ) FROM ' ||
43+ quote_ident(PGT.schemaname)|| '.'||quote_ident(T.relname)|| ';'
44+ FROM pg_class AS S,
45+ pg_depend AS D,
46+ pg_class AS T,
47+ pg_attribute AS C,
48+ pg_tables AS PGT
49+ WHERE S.relkind = 'S'
50+ AND S.oid = D.objid
51+ AND D.refobjid = T.oid
52+ AND D.refobjid = C.attrelid
53+ AND D.refobjsubid = C.attnum
54+ AND T.relname = PGT.tablename
55+ ORDER BY S.relname;` )
56+ if err != nil {
57+ fmt .Printf ("Failed to generate sequence update: %v\n " , err )
58+ return err
59+ }
60+ for _ , r := range results {
61+ for _ , value := range r {
62+ _ , err = x .Exec (value )
63+ if err != nil {
64+ fmt .Printf ("Failed to update sequence: %s Error: %v\n " , value , err )
65+ return err
66+ }
67+ }
68+ }
69+ }
3870 return err
3971}
You can’t perform that action at this time.
0 commit comments