-
-
Notifications
You must be signed in to change notification settings - Fork 24
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 db open
command
#72
Conversation
Discussion: How should we handle app-specific paramters (e.g: ping @swalkinshaw |
By app I'm guessing you mean TablePlus and Sequel Pro for example? I guess we'd have to have some we officially support and hardcode their necessary options? Then we could also let people pass-through whatever extra params they need. |
Yes. What do you think about this style?
Putting the app name last because we can make them optional when #70 is done. The reason is that they can be open in very different ways: TablePlus: Sequal Pro: |
We don't really have other options than your suggestion but I think they should be option flags instead? |
eef5321
to
10ad118
Compare
Help wanted10ad118 introduces Whoever can't stand with my code smell, free feel to make pull requests to my branch.
I have trouble getting ansible outputs from There are lots of boilerplate code . Example:
However, refactoring them affects almost every existing commands. Bash autocompletion doesn't work on my machine. Thus, omitted. Tried to put Same goes to |
3511fcd
to
4f445ad
Compare
🤷♂ I think it looks mostly good overall. Not sure we can really avoid a lot of boilerplate here (and it's Go after all 😛 ). re: subdirectory, Go is weird about this and I don't know the best solution. But for now I'd just name the files |
Ignore this PR until #88 is merged |
Added more tests. Note:
Usage:
If you just installed tableplus or sequel-pro, open them normally at least once before running |
For testing the struct type, I think you want https://golang.org/pkg/reflect/#TypeOf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's already some tests for DBOpenerSequelPro
; wouldn't those work the same way for DBOpenCommand
as well? Just assert on the mock exec command?
|
||
// Template playbook files from package to Trellis | ||
playbookPath := "dump_db_credentials.yml" | ||
writeFile(playbookPath, templates.TrimSpace(dumpDbCredentialsYmlTemplate)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every usage of writeFile
deletes the file after. Maybe we should just make this a more specific writeTempFile
function which also handles the defer delete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we defer the defer
?
If we put defer
inside writeTempFile
, it deletes the files at the end of writeTempFile
instead of the end of func (c *DBOpenCommand) Run(args []string) int
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes good call. We do this:
trellis-cli/trellis/testing.go
Lines 32 to 38 in 54aeb5d
return func() { | |
if err := os.Chdir(old); err != nil { | |
t.Fatalf("err: %s", err) | |
} | |
os.RemoveAll(tempDir) | |
} |
Then it would be called as:
defer writeFile(path, foo)()
if sequelProSpfErr != nil { | ||
return fmt.Errorf("Error creating temporary SequelPro SPF file: %s", sequelProSpfErr) | ||
} | ||
// TODO: [Help Wanted] There is a chance that the SPF file got deleted before SequelPro establish db connection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain this more? Was it getting deleted by the defer
first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was it getting deleted by the defer first?
That is my theory.
If we uncomment the defer
line, sequel pro will open but doesn't pre-fill any db info.
If we comment the defer
line, sequel pro will open with db info pre-filled and try to connect to the db.
I suspect sequel pro needs to read that spf file after launch, but golang deleted the spf too soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes some sense. You could verify by logging like this:
func (o *DBOpenerSequelPro) open(c DBCredentials) (err error) {
# etc
open := execCommand("open", sequelProSpf.Name())
err := cmd.Start()
if err != nil {
log.Fatal(err)
}
log.Printf("running sequel pro...")
err = cmd.Wait()
log.Printf("Command finished with error: %v", err)
}
And then add a log printf to deleteFile
to see when it's actually run compared to the other log lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed my theroy - the SPF file is read twice:
- once by OS to open sequel pro
- once by sequel pro to get db credentials
Newer version of sequel pro shows this error message if SPF is deleted too early:
Error while reading connection data file
Connection data file couldn't be read. (The file “804911772.spf” couldn’t be opened because there is no such file.)
I can work on some tests as well if you want |
It works!
Not sure how to mock the json file - https://github.com/roots/trellis-cli/pull/72/files#diff-a08b51a976e893b57653c908b219ffbcR135
Please do! Thanks! |
I looked into testing and it's going to be very hard... it is possible to have more control over the mock exec command but it's not nice. We'd have to hardcode a conditional in I think there's two solutions:
|
Something like tangrufus/trellis-cli@b83f85e...TangRufus:playbook-struct ? |
Yep that looks like it should do it 👍 . The test struct would mostly be concerned with implementing |
I presume that we want to inject trellis := trellis.NewTrellis(project)
+ playbook := &Playbook{}
c.Commands = map[string]cli.CommandFactory{
"alias": func() (cli.Command, error) {
- return cmd.NewAliasCommand(ui, trellis), nil
+ return cmd.NewAliasCommand(ui, trellis, playbook), nil
}, Am I correct? |
Correct yeah. That's the only place available and you can see examples in |
Question: What are the differences between |
The way I understand it:
I found it was needed for |
The merge was a mistake. Sorry everyone. Reverted in #90 |
Open remote databases via SSH tunnels in your favourite database client.
Requirement
An database client on your local machine registered as
mysql+ssh://
handler, e.g: TablePlusHow does it work?
In a nutshell, it invokes this command on your local machine:
Which database clients are supported?
I've only tested TablePlus.
Sqeual Pro (nightly) supports
mysql://
but seems not support SSH tunnels yetDoes it support vagrant / local databases?
No.
See: #7