-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dump database and import to other supported databases #1388
Comments
Hmm... I think it's kind of database migration thing than a Gogs feature. Maybe dump SQL from PostgreSQL and import to SQLite3? Did some googling: http://manuel.manuelles.nl/blog/2012/01/18/convert-postgresql-to-sqlite/ |
I read the article, and it doesn't apply well to gogs. |
The article link I posted just an example that how migrate between databases. Right now Gogs does not have somewhat in the middle format to support this kind of operation. However, we can change purpose of issue to be: dump database and import to other supported databases. |
I spent some time on fiddling with PostgreSQL and SQLite 3 and migrated the database. |
I've changed title, please check and see if you're OK with it. |
I'm ok with it. |
Could x-orm tools be used perhaps? |
This is an interesting question. The dump will automatically generate create table, create index and insert into SQLs. For all kind of databases, the differences between them are create table and create index. |
Would there be a downside to |
I will try to implement this on xorm via |
@jdroot SQL isn't 100% compatible across all types of databases, but Gogs understands its convetion. @lunny Is it possible to dump SQLite3 and import to MySQL? |
@unknwon I think Yes. The new |
@lunny that sounds cool! |
It's difficult to convert sqlite's datatypes to mysql's datatypes. There are some work to do. |
That's why I suggest this issue to dump a in-middle format specifically for Gogs purpose. |
Another idea, we can generate table creation SQL according Go's struct not from database. And generate Insert SQL from database. I will try this way later. |
I think it is a good idea. |
I just pushed a commit to xorm go-xorm/xorm@4bcbb95, now I think Gogs could implement this feature via var tbs = []interface{}{
new(AccessToken),
//new(DeployKey),
new(Collaboration),
new(Notice),
new(Access),
new(Label),
new(EmailAddress),
new(TeamRepo),
new(TeamUser),
new(OrgUser),
new(HookTask),
new(UpdateTask),
new(Webhook),
}
var tables []*core.Table
for _, tb := range tbs {
tables = append(tables, engine.TableInfo(tb))
}
err = engine.DumpTables(tables, os.Stdout, core.MYSQL)
if err != nil {
panic(err)
} |
Thanks, how to import back? |
|
Got it, I'll try that. |
@unknwon What I meant by my comment earlier was something like the following. Basically, don't deal with SQL at all. (Code might be bad, I am very new to Go) func DumpAllAsGob(filePath string) error {
f, err := os.Create(filePath)
if (err != nil) {
return err
}
defer f.Close()
enc := gob.NewEncoder(f)
for _, table := range tables {
slice := reflect.MakeSlice(reflect.SliceOf(reflect.TypeOf(table)), 0, 0)
slicePointer := reflect.New(slice.Type())
slicePointer.Elem().Set(slice)
sliceInterface := slicePointer.Interface()
err = x.Find(sliceInterface)
if (err == nil) {
enc.Encode(slicePointer.Elem().Interface())
} else {
return err
}
}
return nil
} |
@jdroot Yes, that is my original thought. But if XORM already works with export and import, I don't think gob thing is worth investigating. |
+1 |
This thingie here kinda does that (if you edit the config-file or pass a new one as a flag) develop...bkcsoft:feature/restore-dump coughing |
hello. I'd want to convert ftom mysql to postgresql. Is there a way to do so? In case there is not, and because my gogs is pretty empty (just addes 20 commits to 2 repos), what would I lost to start from scratch? Would be the commit's comments visible to a new gogs deploy with the same git repos? |
Hi @aventrax , forgot to update this issue. This feature has been supported quite a while, you can read more about how to do that: https://discuss.gogs.io/t/how-to-backup-restore-and-migrate/991 |
@unknwon many thanks, i migrated successfully! |
Since SQLite 3 looks ok, I want to remove PostgreSQL which is another piece of software that adds complexity to my system administration.
http://gogs.io/docs/intro/ doesn't tell me how to migrate gogs database.
Can anyone document how to do it on the website?
The text was updated successfully, but these errors were encountered: