Skip to content
This repository has been archived by the owner on Jun 28, 2018. It is now read-only.

MySQL Driver #1

Closed
mattes opened this issue Aug 13, 2014 · 22 comments
Closed

MySQL Driver #1

mattes opened this issue Aug 13, 2014 · 22 comments

Comments

@mattes
Copy link
Owner

mattes commented Aug 13, 2014

No description provided.

@mattes
Copy link
Owner Author

mattes commented Aug 13, 2014

@mattes mattes added the driver label Aug 27, 2014
@mattes
Copy link
Owner Author

mattes commented Sep 16, 2014

@mattes
Copy link
Owner Author

mattes commented Oct 10, 2014

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?

mattes referenced this issue in balboah/migrate Nov 17, 2014
Makes it possible to run several queries in each file.
@daddykotex
Copy link
Contributor

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

@mattes
Copy link
Owner Author

mattes commented Dec 20, 2014

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

@mattes
Copy link
Owner Author

mattes commented Mar 23, 2015

see also #39

@raphaeljlps
Copy link
Contributor

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

@arnehormann
Copy link

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.

@mattes
Copy link
Owner Author

mattes commented Oct 2, 2015

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.

@raphaeljlps
Copy link
Contributor

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

@alecha
Copy link

alecha commented Nov 19, 2015

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!

@mattes
Copy link
Owner Author

mattes commented Nov 19, 2015

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.

@alecha
Copy link

alecha commented Nov 19, 2015

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

@daddykotex
Copy link
Contributor

You can rename the package when you import:

import (  
    MysqlDriver  "mysql" //rename
)

@alecha
Copy link

alecha commented Nov 19, 2015

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

@daddykotex
Copy link
Contributor

Ok, I misunderstood your problem.

@mattes
Copy link
Owner Author

mattes commented Nov 19, 2015

Can you send the panic log?

@alecha
Copy link

alecha commented Nov 19, 2015

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

@alecha
Copy link

alecha commented Dec 3, 2015

any news?

@jonaz
Copy link

jonaz commented Mar 21, 2016

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

@revett
Copy link

revett commented Mar 30, 2016

+1

@dselans
Copy link

dselans commented Sep 20, 2016

Running into the same issue as @alecha.

sigmunau referenced this issue in feideconnect/migrate Sep 28, 2016
use a non-zero exit code when no command is given
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants