Skip to content

Commit f5ebdb5

Browse files
committed
Change database engine to mysql
1 parent 92a0b07 commit f5ebdb5

File tree

9 files changed

+68
-13
lines changed

9 files changed

+68
-13
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,13 @@ jobs:
1414
- run: sudo add-apt-repository ppa:inkscape.dev/stable
1515
- run: sudo apt-get update
1616
- run: sudo apt-get install inkscape -y
17+
- name: Set up MariaDB
18+
id: mariadb
19+
uses: rusher/action-setup-mariadb@v1.6
20+
with:
21+
tag: '11.4'
22+
local: true # Force local installation
23+
root-password: 'myRootPassword'
24+
database: 'myDb'
1725
- run: go build ./cmd/violet/
18-
- run: go test ./...
26+
- run: DB=root:myRootPassword@tcp(127.0.0.1)/maildepo go test ./...

domains/domains_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import (
66
"github.com/1f349/violet/database"
77
_ "github.com/mattn/go-sqlite3"
88
"github.com/stretchr/testify/assert"
9+
"os"
910
"testing"
1011
"time"
1112
)
1213

1314
func TestDomainsNew(t *testing.T) {
14-
db, err := violet.InitDB("file:TestDomainsNew?mode=memory&cache=shared")
15+
db, err := violet.InitDB(os.Getenv("DB"))
1516
assert.NoError(t, err)
1617

1718
domains := New(context.Background(), db, 5*time.Second)
@@ -31,7 +32,7 @@ func TestDomainsNew(t *testing.T) {
3132

3233
func TestDomains_IsValid(t *testing.T) {
3334
// open sqlite database
34-
db, err := violet.InitDB("file:TestDomains_IsValid?mode=memory&cache=shared")
35+
db, err := violet.InitDB(os.Getenv("DB"))
3536
assert.NoError(t, err)
3637

3738
domains := New(context.Background(), db, 5*time.Second)

favicons/favicons_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
_ "github.com/mattn/go-sqlite3"
1111
"github.com/stretchr/testify/assert"
1212
"image/png"
13+
"os"
1314
"testing"
1415
)
1516

@@ -25,7 +26,7 @@ var (
2526
func TestFaviconsNew(t *testing.T) {
2627
getFaviconViaRequest = func(_ string) ([]byte, error) { return exampleSvg, nil }
2728

28-
db, err := violet.InitDB("file:TestFaviconsNew?mode=memory&cache=shared")
29+
db, err := violet.InitDB(os.Getenv("DB"))
2930
assert.NoError(t, err)
3031

3132
favicons := New(db, "inkscape")

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ require (
4040
github.com/davecgh/go-spew v1.1.1 // indirect
4141
github.com/go-jose/go-jose/v4 v4.1.0 // indirect
4242
github.com/go-logfmt/logfmt v0.6.0 // indirect
43+
github.com/go-sql-driver/mysql v1.5.0 // indirect
4344
github.com/hashicorp/errwrap v1.1.0 // indirect
4445
github.com/hashicorp/go-multierror v1.1.1 // indirect
4546
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect

go.sum

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ github.com/1f349/rsa-helper v0.0.2 h1:N/fLQqg5wrjIzG6G4zdwa5Xcv9/jIPutCls9YekZr9
44
github.com/1f349/rsa-helper v0.0.2/go.mod h1:VUQ++1tYYhYrXeOmVFkQ82BegR24HQEJHl5lHbjg7yg=
55
github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=
66
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
7+
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
8+
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
9+
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
10+
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
711
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
812
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
913
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
@@ -33,10 +37,30 @@ github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr
3337
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3438
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3539
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
40+
github.com/dhui/dktest v0.4.4 h1:+I4s6JRE1yGuqflzwqG+aIaMdgXIorCf5P98JnaAWa8=
41+
github.com/dhui/dktest v0.4.4/go.mod h1:4+22R4lgsdAXrDyaH4Nqx2JEz2hLp49MqQmm9HLCQhM=
42+
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
43+
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
44+
github.com/docker/docker v27.2.0+incompatible h1:Rk9nIVdfH3+Vz4cyI/uhbINhEZ/oLmc+CBXmH6fbNk4=
45+
github.com/docker/docker v27.2.0+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
46+
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
47+
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
48+
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
49+
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
50+
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
51+
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
3652
github.com/go-jose/go-jose/v4 v4.1.0 h1:cYSYxd3pw5zd2FSXk2vGdn9igQU2PS8MuxrCOCl0FdY=
3753
github.com/go-jose/go-jose/v4 v4.1.0/go.mod h1:GG/vqmYm3Von2nYiB2vGTXzdoNKE5tix5tuc6iAd+sw=
3854
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
3955
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
56+
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
57+
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
58+
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
59+
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
60+
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
61+
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
62+
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
63+
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
4064
github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI=
4165
github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
4266
github.com/golang-migrate/migrate/v4 v4.18.2 h1:2VSCMz7x7mjyTXx3m2zPokOY82LTRgxK1yQYKo6wWQ8=
@@ -85,6 +109,12 @@ github.com/mattn/go-sqlite3 v1.14.28/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxU
85109
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
86110
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
87111
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
112+
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
113+
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
114+
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
115+
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
116+
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
117+
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
88118
github.com/mrmelon54/certgen v0.0.3 h1:9pF8iZz6woJeiczhT0ku9mkA8sqbhzxvDo3aHgow0xg=
89119
github.com/mrmelon54/certgen v0.0.3/go.mod h1:By4NSWvlke0ENybeJvz+1Vwky5PxdFVPxjOqTdSCCPA=
90120
github.com/mrmelon54/png2ico v1.0.2 h1:KyJd3ATmDjxAJS28MTSf44GxzYnlZ+7KT8SXzGb3sN8=
@@ -97,6 +127,10 @@ github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc
97127
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
98128
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
99129
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
130+
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
131+
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
132+
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
133+
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
100134
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
101135
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
102136
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -127,6 +161,14 @@ github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf
127161
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
128162
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
129163
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
164+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 h1:TT4fX+nBOA/+LUkobKGW1ydGcn+G3vRw9+g5HwCphpk=
165+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0/go.mod h1:L7UH0GbB0p47T4Rri3uHjbpCFYrVrwc1I25QhNPiGK8=
166+
go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw=
167+
go.opentelemetry.io/otel v1.29.0/go.mod h1:N/WtXPs1CNCUEx+Agz5uouwCba+i+bJGFicT8SR4NP8=
168+
go.opentelemetry.io/otel/metric v1.29.0 h1:vPf/HFWTNkPu1aYeIsc98l4ktOQaL6LeSoeV2g+8YLc=
169+
go.opentelemetry.io/otel/metric v1.29.0/go.mod h1:auu/QWieFVWx+DmQOUMgj0F8LHWdgalxXqvp7BII/W8=
170+
go.opentelemetry.io/otel/trace v1.29.0 h1:J/8ZNK4XgR7a21DZUAsbF8pZ5Jcw1VhACmnYt39JTi4=
171+
go.opentelemetry.io/otel/trace v1.29.0/go.mod h1:eHl3w0sp3paPkYstJOmAimxhiFXPg+MMTlEh3nsQgWQ=
130172
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
131173
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
132174
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

initdb.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"errors"
77
"github.com/1f349/violet/database"
88
"github.com/golang-migrate/migrate/v4"
9-
"github.com/golang-migrate/migrate/v4/database/sqlite3"
9+
"github.com/golang-migrate/migrate/v4/database/mysql"
1010
"github.com/golang-migrate/migrate/v4/source/iofs"
1111
)
1212

@@ -18,15 +18,15 @@ func InitDB(p string) (*database.Queries, error) {
1818
if err != nil {
1919
return nil, err
2020
}
21-
dbOpen, err := sql.Open("sqlite3", p)
21+
dbOpen, err := sql.Open("mysql", p)
2222
if err != nil {
2323
return nil, err
2424
}
25-
dbDrv, err := sqlite3.WithInstance(dbOpen, &sqlite3.Config{})
25+
dbDrv, err := mysql.WithInstance(dbOpen, &mysql.Config{})
2626
if err != nil {
2727
return nil, err
2828
}
29-
mig, err := migrate.NewWithInstance("iofs", migDrv, "sqlite3", dbDrv)
29+
mig, err := migrate.NewWithInstance("iofs", migDrv, "mysql", dbDrv)
3030
if err != nil {
3131
return nil, err
3232
}

router/manager_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/stretchr/testify/assert"
1212
"net/http"
1313
"net/http/httptest"
14+
"os"
1415
"testing"
1516
"time"
1617
)
@@ -25,7 +26,7 @@ func (f *fakeTransport) RoundTrip(req *http.Request) (*http.Response, error) {
2526
}
2627

2728
func TestNewManager(t *testing.T) {
28-
db, err := violet.InitDB("file:TestNewManager?mode=memory&cache=shared")
29+
db, err := violet.InitDB(os.Getenv("DB"))
2930
assert.NoError(t, err)
3031

3132
ft := &fakeTransport{}
@@ -61,7 +62,7 @@ func TestNewManager(t *testing.T) {
6162
}
6263

6364
func TestManager_GetAllRoutes(t *testing.T) {
64-
db, err := violet.InitDB("file:TestManager_GetAllRoutes?mode=memory&cache=shared")
65+
db, err := violet.InitDB(os.Getenv("DB"))
6566
assert.NoError(t, err)
6667
m := NewManager(context.Background(), db, nil, 5*time.Second)
6768
a := []error{
@@ -92,7 +93,7 @@ func TestManager_GetAllRoutes(t *testing.T) {
9293
}
9394

9495
func TestManager_GetAllRedirects(t *testing.T) {
95-
db, err := violet.InitDB("file:TestManager_GetAllRedirects?mode=memory&cache=shared")
96+
db, err := violet.InitDB(os.Getenv("DB"))
9697
assert.NoError(t, err)
9798
m := NewManager(context.Background(), db, nil, 5*time.Second)
9899
a := []error{

servers/https_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/stretchr/testify/assert"
1414
"net/http"
1515
"net/http/httptest"
16+
"os"
1617
"sync"
1718
"testing"
1819
"time"
@@ -27,7 +28,7 @@ func (f *fakeTransport) RoundTrip(_ *http.Request) (*http.Response, error) {
2728
}
2829

2930
func TestNewHttpsServer_RateLimit(t *testing.T) {
30-
db, err := violet.InitDB("file:TestNewHttpsServer_RateLimit?mode=memory&cache=shared")
31+
db, err := violet.InitDB(os.Getenv("DB"))
3132
assert.NoError(t, err)
3233

3334
ft := &fakeTransport{}

sqlc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: "2"
22
sql:
3-
- engine: sqlite
3+
- engine: mysql
44
queries: database/queries
55
schema: database/migrations
66
gen:

0 commit comments

Comments
 (0)