aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/restore.go2
-rw-r--r--gogs.go2
-rw-r--r--models/models.go17
-rw-r--r--templates/.VERSION2
4 files changed, 19 insertions, 4 deletions
diff --git a/cmd/restore.go b/cmd/restore.go
index e76744d9..4e000422 100644
--- a/cmd/restore.go
+++ b/cmd/restore.go
@@ -83,7 +83,7 @@ func runRestore(c *cli.Context) error {
// Database
dbDir := path.Join(archivePath, "db")
- if err = models.ImportDatabase(dbDir); err != nil {
+ if err = models.ImportDatabase(dbDir, c.Bool("verbose")); err != nil {
log.Fatal(0, "Fail to import database: %v", err)
}
diff --git a/gogs.go b/gogs.go
index 61da6456..23a96910 100644
--- a/gogs.go
+++ b/gogs.go
@@ -16,7 +16,7 @@ import (
"github.com/gogits/gogs/pkg/setting"
)
-const APP_VER = "0.11.10.0517"
+const APP_VER = "0.11.11.0521"
func init() {
setting.AppVer = APP_VER
diff --git a/models/models.go b/models/models.go
index 98a4fd23..088d8f58 100644
--- a/models/models.go
+++ b/models/models.go
@@ -302,7 +302,9 @@ func DumpDatabase(dirPath string) (err error) {
}
// ImportDatabase imports data from backup archive.
-func ImportDatabase(dirPath string) (err error) {
+func ImportDatabase(dirPath string, verbose bool) (err error) {
+ snakeMapper := core.SnakeMapper{}
+
// Purposely create a local variable to not modify global variable
tables := append(tables, new(Version))
for _, table := range tables {
@@ -312,6 +314,10 @@ func ImportDatabase(dirPath string) (err error) {
continue
}
+ if verbose {
+ log.Trace("Importing table '%s'...", tableName)
+ }
+
if err = x.DropTables(table); err != nil {
return fmt.Errorf("fail to drop table '%s': %v", tableName, err)
} else if err = x.Sync2(table); err != nil {
@@ -353,6 +359,15 @@ func ImportDatabase(dirPath string) (err error) {
return fmt.Errorf("fail to insert strcut: %v", err)
}
}
+
+ // PostgreSQL needs manually reset table sequence for auto increment keys
+ if setting.UsePostgreSQL {
+ rawTableName := snakeMapper.Obj2Table(tableName)
+ seqName := rawTableName + "_id_seq"
+ if _, err = x.Exec(fmt.Sprintf(`SELECT setval('%s', COALESCE((SELECT MAX(id)+1 FROM "%s"), 1), false);`, seqName, rawTableName)); err != nil {
+ return fmt.Errorf("fail to reset table '%s' sequence: %v", rawTableName, err)
+ }
+ }
}
return nil
}
diff --git a/templates/.VERSION b/templates/.VERSION
index 48f12621..90070c3b 100644
--- a/templates/.VERSION
+++ b/templates/.VERSION
@@ -1 +1 @@
-0.11.10.0517 \ No newline at end of file
+0.11.11.0521 \ No newline at end of file