gobuffalo / cli

The Buffalo CLI
19 stars 24 forks source link

Issues with sqlite3 (and solutions) while getting started with Buffalo #209

Closed rohfle closed 2 years ago

rohfle commented 2 years ago

This is the first time I've played around with buffalo. I had trouble getting sqlite3 working as a database while following the getting started docs and thought I would share what I did.

What I did From https://gobuffalo.io/documentation/getting_started/installation/ go install -tags sqlite github.com/gobuffalo/cli/cmd/buffalo@v0.18.8 - OK

From https://gobuffalo.io/documentation/getting_started/new-project/ and https://dev.to/alexmercedcoder/api-with-go-buffalo-in-2021-from-zero-to-deploy-5642 buffalo new project1 --api - OK

Then I wanted to change database type to sqlite for development in database.yml

development:
  dialect: "sqlite3"
  database: development.sqlite

But I got this error when running buffalo dev

buffalo: 2022/08/07 08:37:00 === Rebuild on: :start: ===
buffalo: 2022/08/07 08:37:00 === Running: go build -v -tags development -o tmp/project1-build ./cmd/app (PID: 615572) ===
buffalo: 2022/08/07 08:37:01 === Building Completed (PID: 615572) (Time: 1.093997852s) ===
buffalo: 2022/08/07 08:37:01 === Running: tmp/project1-build (PID: 615635) ===
[POP] 2022/08/07 08:37:01 warn - unable to load connection development: could not create new connection: sqlite3 support was not compiled into the binary
2022/08/07 08:37:01 could not find connection named development
buffalo: 2022/08/07 08:37:01 === exit status 1
2022/08/07 08:37:01 could not find connection named development

To fix this, I have to browse through issues and slack and read between the lines. I set the following in config/buffalo-app.toml

with_sqlite = true

And set the following in config/buffalo-plugins.toml

[[plugin]]
  binary = "buffalo-pop"
  go_get = "github.com/gobuffalo/buffalo-pop/v3@latest"
  tags = ["sqlite"]

Then buffalo dev works

buffalo: 2022/08/07 08:44:24 === Rebuild on: :start: ===
buffalo: 2022/08/07 08:44:24 === Running: go build -v -tags development sqlite -o tmp/project1-build ./cmd/app (PID: 616136) ===
buffalo: 2022/08/07 08:44:27 === Building Completed (PID: 616136) (Time: 2.496160018s) ===
buffalo: 2022/08/07 08:44:27 === Running: tmp/project1-build (PID: 616211) ===
DEBU[2022-08-07T08:44:27+12:00] starting application
INFO[2022-08-07T08:44:27+12:00] starting simple server on 127.0.0.1:3002
INFO[2022-08-07T08:44:27+12:00] starting Simple background worker

Somewhere I learn about using the --db-type arg like buffalo new project1 --db-type sqlite3, which gets me to the same point. I have to change database.yml as I want to use sqlite3 for development but not for testing and production. Also paths are absolute (not relative to project directory), so if the project moves this would need to be updated.

When I try to run buffalo pop migrate I get

pop v6.0.5

[POP] 2022/08/07 08:56:54 warn - unable to load connection development: could not create new connection: sqlite3 support was not compiled into the binary
There is no connection named development defined!

which soda and which pop gives no result so I assume that pop is embedded in buffalo. But weird that sqlite3 support is present for dev but not for pop. Not sure how to proceed with this one.

rohfle commented 2 years ago

I worked out buffalo pop migrate is executing buffalo-pop as a child process

strace -f buffalo pop migrate 2>&1 | grep execve
[pid 648698] execve("/usr/local/bin/go", ["go", "env", "GOPATH"], 0xc0000da000 /* 52 vars */ <unfinished ...>
[pid 648698] <... execve resumed>)      = 0
[pid 648706] execve("/home/user/go/bin/buffalo-pop", ["/home/user/go/bin/buffa"..., "pop", "migrate"], 0xc00054c540 /* 54 vars */ <unfinished ...>
[pid 648706] <... execve resumed>)      = 0

To fix the issue I ran

go install -tags sqlite -v github.com/gobuffalo/buffalo-pop/v3

buffalo pop migrate now works

pop v6.0.5

[POP] 2022/08/07 14:18:25 info - Migrations already up to date, nothing to apply
[POP] 2022/08/07 14:18:25 info - 0.0082 seconds
[POP] 2022/08/07 14:18:25 info - dumped schema for development.sqlite
sio4 commented 2 years ago

Thank you for filing an issue with details.

Yes, the CLI (and the plugins) will be installed without sqlite3 support if --db-type argument is not given. Like your case, if the user uses different databases for the development and the production, these manual steps need to be performed by the user themselves. (It is similar to the users who use sqlite3 on one project and use the other database in another project developed on the same development workstation since the plugin can be reinstalled by the other project.) Actually, this is the same for me since I love to use sqlite3. :-)

This issue is known but slightly tricky. The discussion about it is on https://github.com/gobuffalo/cli/discussions/184 for your information. (I will close this issue and please feel free to add your comments on the discussion)