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

Add schema parsing for unix scheme urls #2847

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

LudvigLundberg
Copy link

Fix for #2472

Faced the same issue (altough with atlas migrate) when trying to migrate through a unix socket, seems the issue is here:

return &sqlclient.URL{URL: u, DSN: dsn(u), Schema: strings.TrimPrefix(u.Path, "/")}

Since the url path for unix sockets can contain multiple / characters.

Steps to reproduce issue (tested on macOS):

brew install mysql
mysql.server start
mysql -u root

# mysql 
create schema test;

# in atlas cmd directory, current master branch
go build .
./atlas schema inspect -u "mysql+unix://root@/tmp/mysql.sock?database=test"

# Error: mysql: schema "tmp/mysql.sock" was not found

git checkout fix-unix-schema-parse
go build .
./atlas schema inspect -u "mysql+unix://root@/tmp/mysql.sock?database=test"

# schema "test" {
#   charset = "utf8mb4"
#   collate = "utf8mb4_0900_ai_ci"
# } 

There is a function in the go-sql-driver/mysql that could be used to parse the DSN and extract the schema, but didn't want to add another dependency to this repo without approval so kept it simple here!

Feel free to suggest improvements or comments on the code, I don't have all the context of atlas so might have missed something! @ttc0419 could maybe have a look and see if it solved the issue for them as well!

@a8m a8m self-requested a review June 7, 2024 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant