Code Monkey home page Code Monkey logo

Comments (22)

jonaz avatar jonaz commented on May 20, 2024 4

What about this?
https://github.com/go-sql-driver/mysql#multistatements

from migrate.

alecha avatar alecha commented on May 20, 2024 1

panic: sql: Register called twice for driver mysql
goroutine 1 [running]:
database/sql.Register(0x71ff90, 0x5, 0xc6c920, 0xafb488)
/usr/local/go/src/database/sql/sql.go:41 +0x181
github.com/go-sql-driver/mysql.init.1()
/Users/alessiocavaleri/Documents/Code/go/src/github.com/go-sql-driver/mysql/driver.go:148 +0x71
github.com/go-sql-driver/mysql.init()
/Users/alessiocavaleri/Documents/Code/go/src/github.com/go-sql-driver/mysql/utils.go:973 +0x61c
github.com/mattes/migrate/driver/mysql.init()
/Users/alessiocavaleri/Documents/Code/go/src/github.com/mattes/migrate/driver/mysql/mysql.go:185 +0x5e
github.com/empatica/web_embrace_api/database.init()
/Users/alessiocavaleri/Documents/Code/go/src/github.com/empatica/web_embrace_api/database/userWatchdog.go:65 +0x6c
github.com/empatica/web_embrace_api/controllers.init()
/Users/alessiocavaleri/Documents/Code/go/src/github.com/empatica/web_embrace_api/controllers/zipperController.go:53 +0x79 main.init()
/Users/alessiocavaleri/Documents/Code/go/src/github.com/empatica/web_embrace_api/embrace_api/main.go:75 +0x62

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1696 +0x1

from migrate.

mattes avatar mattes commented on May 20, 2024

https://github.com/go-sql-driver/mysql/

from migrate.

mattes avatar mattes commented on May 20, 2024

see https://github.com/mattes/migrate/tree/mysql

from migrate.

mattes avatar mattes commented on May 20, 2024

I added experimental support for mysql migrations. The issue is that there is no golang mysql driver that supports multiple sql statements per query. So the mysql driver splits sql statements by semicolons ;.

Goose uses some custom split strings to format sql migrations. I really would like to avoid that. Is there a golang mysql driver that supports multiple sql statements?

from migrate.

daddykotex avatar daddykotex commented on May 20, 2024

Hi

I like what you did, great job! Keep up the good work.

I came here to ask you a little question, I'm using migrate in my project with MySQL. I know it's still under development, no worries there. It came to my attention that when my program runs and that there is an up migration to do (I added a table for example), migrate does it just fine, no problem with that, but I can't halt my app with ^C anymore.

If migrate runs something against my database, then I can't stop my program anymore. I don't know if it is related to the MySQL driver, but maybe you can point me in a direction while I'm looking into it, it could go faster! It might be on my side too.

Thanks, a lot, and by the way, I looked into the driver and tried a pull request to handle multiple statement but it was closed. You can see my pull request here : go-sql-driver/mysql#296

from migrate.

mattes avatar mattes commented on May 20, 2024

Thanks!

but I can't halt my app with ^C anymore.

When a migration is running and you hit ^C migrate will wait until the current migration has been applied. But it's a good point. Sometimes you really want to force an exit regardless of running migrations. I guess hitting ^C twice should exit immediately. This isn't implemented though.

I looked into the driver and tried a pull request to handle multiple statement but it was closed.

It's too bad database/sql does not support multiple statements. I think @arnehormann put it in a nutshell:

The good news: MySQL can do this on its own. We only have to set two flags when a connection is established. The bad news: database/sql does not support it in any way. As it's unsupported by database/sql, we won't support it either

from migrate.

mattes avatar mattes commented on May 20, 2024

see also #39

from migrate.

raphaeljlps avatar raphaeljlps commented on May 20, 2024

hey @mattes what do you think about mymysql?
I am thinking about implementing the Driver interface for it, do you think is worth ?

from migrate.

arnehormann avatar arnehormann commented on May 20, 2024

For cases like yours, you can also use the driver by its database/sql/driver interface (mysql.MySQLDriver{}.Open(dsn)).
That way, you get a single-connection session instead of a connection pool - with a little more setup boilerplate.
I think there's some ORM tools already doing so.

from migrate.

mattes avatar mattes commented on May 20, 2024

I never used it, but https://github.com/ziutek/mymysql#example-4---multi-statement--multi-result looks promising. If you want to give it a try, go for it. Will definitely merge if it works.

from migrate.

raphaeljlps avatar raphaeljlps commented on May 20, 2024

okay, @mattes I will start to work on it soon.

from migrate.

alecha avatar alecha commented on May 20, 2024

I'd like to use migrate as a library in my go package, but I've seen that in the init function you call

driver.RegisterDriver("mysql", &Driver{})

and this cause a panic because in the same package I also have to import the mysql package that does the same.

There is a way to prevent that?

Thanks!

from migrate.

mattes avatar mattes commented on May 20, 2024

I'm surprised, because the mysql driver registers with https://github.com/mattes/migrate/blob/master/driver/registry.go which is unrelated from the any other mysql driver.

from migrate.

alecha avatar alecha commented on May 20, 2024

Actually the "mysql" name is used both by your driver and by go-sql-driver package, am I missing something?

https://github.com/go-sql-driver/mysql/blob/master/driver.go

from migrate.

daddykotex avatar daddykotex commented on May 20, 2024

You can rename the package when you import:

import (  
    MysqlDriver  "mysql" //rename
)

from migrate.

alecha avatar alecha commented on May 20, 2024

This won't solve the problem, because in these two files I'm importing they are creating a driver with the same name, as it will panic

https://github.com/go-sql-driver/mysql/blob/master/driver.go : line 148
https://github.com/mattes/migrate/blob/master/driver/mysql/mysql.go : line 184

from migrate.

daddykotex avatar daddykotex commented on May 20, 2024

Ok, I misunderstood your problem.

from migrate.

mattes avatar mattes commented on May 20, 2024

Can you send the panic log?

from migrate.

alecha avatar alecha commented on May 20, 2024

any news?

from migrate.

revett avatar revett commented on May 20, 2024

+1

from migrate.

dselans avatar dselans commented on May 20, 2024

Running into the same issue as @alecha.

from migrate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.