Skip to content
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

Closed
crocket opened this issue Jul 25, 2015 · 28 comments
Closed

Dump database and import to other supported databases #1388

crocket opened this issue Jul 25, 2015 · 28 comments
Labels
🎯 feature Categorizes as related to a new feature

Comments

@crocket
Copy link

crocket commented Jul 25, 2015

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?

@unknwon unknwon added 📦 deployment Related to deployments status: needs feedback Tell me more about it labels Jul 25, 2015
@unknwon
Copy link
Member

unknwon commented Jul 25, 2015

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/

@crocket
Copy link
Author

crocket commented Jul 25, 2015

I read the article, and it doesn't apply well to gogs.
It seems like a non-intuitive administration task.

@unknwon
Copy link
Member

unknwon commented Jul 25, 2015

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.

@crocket
Copy link
Author

crocket commented Jul 25, 2015

I spent some time on fiddling with PostgreSQL and SQLite 3 and migrated the database.
But, I am not sure whether the migration caused any glitches.
Perhaps, it should become a feature request.

@unknwon unknwon added 🎯 feature Categorizes as related to a new feature and removed 📦 deployment Related to deployments question labels Jul 25, 2015
@unknwon unknwon added this to the 0.6.5 milestone Jul 25, 2015
@unknwon unknwon changed the title How do I migrate gogs database from PostgreSQL to SQLite 3? Dump database and import to other supported databases Jul 25, 2015
@unknwon
Copy link
Member

unknwon commented Jul 25, 2015

I've changed title, please check and see if you're OK with it.

@crocket
Copy link
Author

crocket commented Jul 25, 2015

I'm ok with it.

@unknwon unknwon modified the milestones: 0.6.7, 0.7.0 Aug 11, 2015
@unknwon unknwon modified the milestones: 0.8.0, 0.7.0 Sep 3, 2015
@unknwon unknwon removed the status: needs feedback Tell me more about it label Dec 18, 2015
@unknwon unknwon mentioned this issue Jan 5, 2016
@unknwon unknwon removed this from the 0.10.0 milestone Feb 7, 2016
@slaskis
Copy link

slaskis commented Feb 16, 2016

Could x-orm tools be used perhaps?

@lunny
Copy link
Contributor

lunny commented Feb 16, 2016

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.

@jdroot
Copy link

jdroot commented Feb 29, 2016

Would there be a downside to gogs dump dumping serialized structs instead of SQL? An import/restore feature could then be created that was database agnostic.

@lunny
Copy link
Contributor

lunny commented Feb 29, 2016

I will try to implement this on xorm via engine.DumpAll(w, dbtype). @unknwon

@unknwon
Copy link
Member

unknwon commented Feb 29, 2016

Would there be a downside to gogs dump dumping serialized structs instead of SQL? An import/restore feature could then be created that was database agnostic.

@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?

@lunny
Copy link
Contributor

lunny commented Feb 29, 2016

@unknwon I think Yes. The new DumpAll method could dump SQL to any xorm supported databases.

@unknwon
Copy link
Member

unknwon commented Feb 29, 2016

@lunny that sounds cool!

@lunny
Copy link
Contributor

lunny commented Feb 29, 2016

It's difficult to convert sqlite's datatypes to mysql's datatypes. There are some work to do.

@unknwon
Copy link
Member

unknwon commented Feb 29, 2016

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.

@lunny
Copy link
Contributor

lunny commented Feb 29, 2016

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.

@unknwon
Copy link
Member

unknwon commented Feb 29, 2016

Another idea, we can generate table creation SQL according Go's struct not from database.

I think it is a good idea.

@lunny
Copy link
Contributor

lunny commented Feb 29, 2016

I just pushed a commit to xorm go-xorm/xorm@4bcbb95, now I think Gogs could implement this feature via DumpTables, the usage is below:

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)
    }

@unknwon

@unknwon
Copy link
Member

unknwon commented Feb 29, 2016

Thanks, how to import back?

@lunny
Copy link
Contributor

lunny commented Feb 29, 2016

engine.Import or engine.ImportFile.

@unknwon
Copy link
Member

unknwon commented Feb 29, 2016

Got it, I'll try that.

@unknwon unknwon added this to the 0.10.0 milestone Feb 29, 2016
@jdroot
Copy link

jdroot commented Feb 29, 2016

@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
}

@unknwon
Copy link
Member

unknwon commented Feb 29, 2016

@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.

@FyinInc
Copy link

FyinInc commented May 11, 2016

+1

@bkcsoft
Copy link
Contributor

bkcsoft commented May 13, 2016

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

@unknwon unknwon modified the milestones: 0.10.0, 0.11.0 Jul 16, 2016
@unknwon unknwon removed this from the 0.11.0 milestone Feb 18, 2017
@aventrax
Copy link

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?

@unknwon unknwon added this to the 0.12 milestone Sep 21, 2017
@unknwon
Copy link
Member

unknwon commented Sep 21, 2017

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 unknwon closed this as completed Sep 21, 2017
@aventrax
Copy link

@unknwon many thanks, i migrated successfully!

@unknwon unknwon removed this from the 0.13 milestone Nov 26, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🎯 feature Categorizes as related to a new feature
Projects
None yet
Development

No branches or pull requests

8 participants