- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
add support for sql migrations
Showing
45 changed files
with
439 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//go:build integration | ||
// +build integration | ||
|
||
package cli_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/keygen-sh/keygen-relay/cli" | ||
"github.com/rogpeppe/go-internal/testscript" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
code := testscript.RunMain(m, map[string]func() int{ | ||
"relay": func() int { | ||
return cli.Run() | ||
}, | ||
}) | ||
|
||
os.Exit(code) | ||
} | ||
|
||
func TestIntegration(t *testing.T) { | ||
t.Parallel() | ||
|
||
testscript.Run(t, testscript.Params{ | ||
Dir: "testdata", | ||
RequireExplicitExec: true, | ||
TestWork: true, | ||
Setup: setup, | ||
}) | ||
} | ||
|
||
func setup(env *testscript.Env) error { | ||
setupFixtures(env) | ||
setupEnv(env) | ||
|
||
return nil | ||
} | ||
|
||
func setupFixtures(env *testscript.Env) error { | ||
fixtures := []string{ | ||
"license.lic", | ||
"license_2.lic", | ||
} | ||
|
||
for _, fixture := range fixtures { | ||
if err := copyFile(filepath.Join("testdata", fixture), filepath.Join(env.WorkDir, fixture)); err != nil { | ||
return fmt.Errorf("failed to copy fixture %s: %w", fixture, err) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func setupEnv(env *testscript.Env) error { | ||
// TODO(ezekg) make prestine env | ||
return nil | ||
} | ||
|
||
func copyFile(src, dst string) error { | ||
input, err := os.ReadFile(src) | ||
if err != nil { | ||
return fmt.Errorf("unable to read file %s: %w", src, err) | ||
} | ||
|
||
if err := os.WriteFile(dst, input, 0644); err != nil { | ||
return fmt.Errorf("unable to write file to %s: %w", dst, err) | ||
} | ||
|
||
return nil | ||
} |
14 changes: 7 additions & 7 deletions
14
testdata/claim_conflict.txt → cli/testdata/claim_conflict.test.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
# Add the license | ||
# add the license | ||
exec relay add --file license.lic --key 9E32DD-D8CC22-771926-C2D834-C506DC-V3 --public-key e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788 | ||
|
||
# Set a port as environment variable | ||
# set a port as environment variable | ||
env PORT=65001 | ||
|
||
# Start the server with heartbeat disabled | ||
# start the server with heartbeat disabled | ||
exec relay serve --port $PORT --no-heartbeats &server_process_test& | ||
|
||
# Wait for the server to start | ||
# wait for the server to start | ||
exec sleep 1 | ||
|
||
# Claim the license for the first time and check status code directly | ||
# claim the license for the first time and check status code directly | ||
exec curl -s -o /dev/null -w "%{http_code}" -X PUT http://localhost:$PORT/v1/nodes/test_fingerprint | ||
stdout '201' | ||
|
||
# Claim the license again with the same fingerprint and check status code directly | ||
# claim the license again with the same fingerprint and check status code directly | ||
exec curl -s -o /dev/null -w "%{http_code}" -X PUT http://localhost:$PORT/v1/nodes/test_fingerprint | ||
stdout '409' | ||
|
||
# Kill the process (stop the server) | ||
# kill the process (stop the server) | ||
kill server_process_test |
18 changes: 9 additions & 9 deletions
18
testdata/claim_license_conflict.txt → cli/testdata/claim_license_conflict.test.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
# Add the license | ||
# add the license | ||
exec relay add --file license.lic --key 9E32DD-D8CC22-771926-C2D834-C506DC-V3 --public-key e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788 | ||
|
||
# Set a port as environment variable | ||
# set a port as environment variable | ||
env PORT=65002 | ||
|
||
# Start the server with heartbeat disabled | ||
# start the server with heartbeat disabled | ||
exec relay serve --port $PORT --no-heartbeats &server_process_test& | ||
|
||
# Wait for the server to start | ||
# wait for the server to start | ||
exec sleep 1 | ||
|
||
# Claim the license for the first time | ||
# claim the license for the first time | ||
exec curl -s -o /dev/null -w "%{http_code}" -X PUT http://localhost:$PORT/v1/nodes/test_fingerprint | ||
stdout '201' | ||
|
||
# Claim the license again with the same fingerprint | ||
# claim the license again with the same fingerprint | ||
exec curl -s -o response.txt -w "%{http_code}" -X PUT http://localhost:$PORT/v1/nodes/test_fingerprint | ||
|
||
# Expect a conflict response with status code 409 and error message | ||
# expect a conflict response with status code 409 and error message | ||
stdout '409' | ||
|
||
exec grep '{"error":"License claim conflict, heartbeat disabled"}' response.txt | ||
exec grep '{"error":"failed to claim license due to conflict"}' response.txt | ||
|
||
# Kill the process (stop the server) | ||
# kill the process (stop the server) | ||
kill server_process_test |
14 changes: 7 additions & 7 deletions
14
testdata/claim_license_extended.txt → cli/testdata/claim_license_extended.test.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
# Add the license | ||
# add the license | ||
exec relay add --file license.lic --key 9E32DD-D8CC22-771926-C2D834-C506DC-V3 --public-key e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788 | ||
|
||
# Set a port as environment variable | ||
# set a port as environment variable | ||
env PORT=65003 | ||
|
||
# Start the server with heartbeat enabled (for extension to work) | ||
# start the server with heartbeat enabled (for extension to work) | ||
exec relay serve --port $PORT &server_process_test& | ||
|
||
# Wait for the server to start | ||
# wait for the server to start | ||
exec sleep 1 | ||
|
||
# Claim a license for the first time | ||
# claim a license for the first time | ||
exec curl -s -o /dev/null -w "%{http_code}" -X PUT http://localhost:$PORT/v1/nodes/test_fingerprint | ||
stdout '201' | ||
|
||
# Claim the license again with the same fingerprint to trigger an extension | ||
# claim the license again with the same fingerprint to trigger an extension | ||
exec curl -s -o response.txt -w "%{http_code}" -X PUT http://localhost:$PORT/v1/nodes/test_fingerprint | ||
stdout '202' | ||
|
||
# Kill the process (stop the server) | ||
# kill the process (stop the server) | ||
kill server_process_test |
18 changes: 9 additions & 9 deletions
18
testdata/claim_license_lifo_strategy.txt → ...data/claim_license_lifo_strategy.test.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
# Add the first license | ||
# add the first license | ||
exec relay add --file license.lic --key 9E32DD-D8CC22-771926-C2D834-C506DC-V3 --public-key e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788 | ||
|
||
# Give a pause between adding licenses | ||
# give a pause between adding licenses | ||
exec sleep 1 | ||
|
||
# Add the second license | ||
# add the second license | ||
exec relay add --file license_2.lic --key 9A96B8-FD08CD-8C433B-7657C8-8A8655-V3 --public-key e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788 | ||
|
||
# Set a port and strategy as environment variables | ||
# set a port and strategy as environment variables | ||
env PORT=65004 | ||
env STRATEGY=lifo | ||
|
||
# Start the server with FIFO strategy | ||
# start the server with FIFO strategy | ||
exec relay serve --port $PORT --strategy $STRATEGY &server_process_test& | ||
|
||
# Wait for the server to start | ||
# wait for the server to start | ||
exec sleep 1 | ||
|
||
# Claim a license (LIFO: should return the last license) | ||
# claim a license (LIFO: should return the last license) | ||
exec curl -s -o response.txt -w "%{http_code}" -X PUT http://localhost:$PORT/v1/nodes/test_fingerprint | ||
|
||
# Expect the first license to be returned | ||
# expect the first license to be returned | ||
exec grep '"license_file":' response.txt | ||
exec grep '"license_key":"9A96B8-FD08CD-8C433B-7657C8-8A8655-V3"' response.txt | ||
|
||
# Kill the process (stop the server) | ||
# kill the process (stop the server) | ||
kill server_process_test |
16 changes: 8 additions & 8 deletions
16
testdata/claim_license_success.txt → cli/testdata/claim_license_success.test.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
|
||
|
||
# Add the license | ||
# add the license | ||
exec relay add --file license.lic --key 9E32DD-D8CC22-771926-C2D834-C506DC-V3 --public-key e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788 | ||
|
||
# Set a port as environment variable | ||
# set a port as environment variable | ||
env PORT=65005 | ||
|
||
# Start the server with heartbeat disabled | ||
# start the server with heartbeat disabled | ||
exec relay serve --port $PORT &server_process_test& | ||
|
||
# Wait for the server to start | ||
# wait for the server to start | ||
exec sleep 1 | ||
|
||
# Claim a license | ||
# claim a license | ||
exec curl -s -o response.txt -w "%{http_code}" -X PUT http://localhost:$PORT/v1/nodes/test_fingerprint | ||
|
||
# Expect a success response with status code 201 | ||
# expect a success response with status code 201 | ||
stdout '201' | ||
|
||
# Check that the response contains license_file and license_key fields (using grep) | ||
# check that the response contains license_file and license_key fields (using grep) | ||
exec grep '"license_file":' response.txt | ||
exec grep '"license_key":' response.txt | ||
|
||
# Kill the process (stop the server) | ||
# kill the process (stop the server) | ||
kill server_process_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# start the server without adding any licenses | ||
env PORT=65006 | ||
exec relay serve --port $PORT &server_process_test& | ||
|
||
# wait for the server to start | ||
exec sleep 1 | ||
|
||
# attempt to claim a license when none are available | ||
exec curl -s -o response.txt -w "%{http_code}" -X PUT http://localhost:$PORT/v1/nodes/test_fingerprint | ||
|
||
# expect a gone response with status code 410 and error message | ||
stdout '410' | ||
exec grep 'no licenses available' response.txt | ||
|
||
# kill the process (stop the server) | ||
kill server_process_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
# Add the license | ||
# add the license | ||
exec relay add --file license.lic --key 9E32DD-D8CC22-771926-C2D834-C506DC-V3 --public-key e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788 | ||
|
||
# Expect output indicating success | ||
stdout 'License added successfully.' | ||
# expect output indicating success | ||
stdout 'license added successfully' | ||
|
||
# List licenses to confirm | ||
# list licenses to confirm | ||
exec relay ls --plain | ||
|
||
# Expect the license to be listed | ||
# expect the license to be listed | ||
stdout 'dcea31a4-1664-4633-9f52-4a1b0b5ea2ef' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
# Add the license | ||
# add the license | ||
exec relay add --file license.lic --key 9E32DD-D8CC22-771926-C2D834-C506DC-V3 --public-key e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788 | ||
|
||
# Confirm the license is added | ||
# confirm the license is added | ||
exec relay ls --plain | ||
stdout 'dcea31a4-1664-4633-9f52-4a1b0b5ea2ef' | ||
|
||
# Delete the license | ||
# delete the license | ||
exec relay del --license dcea31a4-1664-4633-9f52-4a1b0b5ea2ef | ||
|
||
# Expect output indicating success | ||
stdout 'License deleted successfully.' | ||
# expect output indicating success | ||
stdout 'license deleted successfully' | ||
|
||
# Verify the license is deleted | ||
# verify the license is deleted | ||
exec relay ls --plain | ||
stdout 'No licenses found.' | ||
stdout 'no licenses found' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
# Add the license | ||
# add the license | ||
exec relay add --file license.lic --key 9E32DD-D8CC22-771926-C2D834-C506DC-V3 --public-key e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788 | ||
|
||
# Set a port as environment variable | ||
# set a port as environment variable | ||
env PORT=65007 | ||
|
||
# Start the server in the background with the environment variable | ||
# start the server in the background with the environment variable | ||
exec relay serve --port $PORT &server_process& | ||
|
||
# Wait for the server to start | ||
# wait for the server to start | ||
exec sleep 1 | ||
|
||
# Claim a license using the port from the environment variable | ||
# claim a license using the port from the environment variable | ||
exec curl -s -X PUT http://localhost:$PORT/v1/nodes/test_fingerprint | ||
|
||
# Expect license data in the response | ||
# expect license data in the response | ||
stdout '"license_file":' | ||
|
||
# Release the license | ||
# release the license | ||
exec curl -s -X DELETE http://localhost:$PORT/v1/nodes/test_fingerprint | ||
|
||
# Expect no content in the response | ||
# expect no content in the response | ||
stdout '' | ||
|
||
# Kill the process (stop the server) | ||
# kill the process (stop the server) | ||
kill server_process |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# Add the license | ||
# add the license | ||
exec relay add --file license.lic --key 9E32DD-D8CC22-771926-C2D834-C506DC-V3 --public-key e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788 | ||
|
||
# Get statistics of the license | ||
# get statistics of the license | ||
exec relay stat --license dcea31a4-1664-4633-9f52-4a1b0b5ea2ef --plain | ||
|
||
# Expect output containing the license details | ||
# expect output containing the license details | ||
stdout 'dcea31a4-1664-4633-9f52-4a1b0b5ea2ef' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
exec relay version | ||
|
||
# should use the dev version | ||
stdout '<not set>' |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# start the server | ||
env PORT=65008 | ||
exec relay serve --port $PORT &server_process_test& | ||
|
||
# wait for the server to start | ||
exec sleep 1 | ||
|
||
# attempt to release a license that was never claimed | ||
exec curl -s -o response.txt -w "%{http_code}" -X DELETE http://localhost:$PORT/v1/nodes/test_fingerprint | ||
|
||
# expect a not found response with status code 404 and error message | ||
stdout '404' | ||
exec grep '{"error":"claim not found"}' response.txt | ||
|
||
# kill the process (stop the server) | ||
kill server_process_test |
14 changes: 7 additions & 7 deletions
14
testdata/release_license_success.txt → ...testdata/release_license_success.test.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
# Add the license | ||
# add the license | ||
exec relay add --file license.lic --key 9E32DD-D8CC22-771926-C2D834-C506DC-V3 --public-key e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788 | ||
|
||
# Set a port as environment variable | ||
# set a port as environment variable | ||
env PORT=65009 | ||
|
||
# Start the server with heartbeat disabled | ||
# start the server with heartbeat disabled | ||
exec relay serve --port $PORT &server_process_test& | ||
|
||
# Wait for the server to start | ||
# wait for the server to start | ||
exec sleep 1 | ||
|
||
# Claim a license | ||
# claim a license | ||
exec curl -s -o /dev/null -w "%{http_code}" -X PUT http://localhost:$PORT/v1/nodes/test_fingerprint | ||
stdout '201' | ||
|
||
# Release the license | ||
# release the license | ||
exec curl -s -o /dev/null -w "%{http_code}" -X DELETE http://localhost:$PORT/v1/nodes/test_fingerprint | ||
stdout '204' | ||
|
||
# Kill the process (stop the server) | ||
# kill the process (stop the server) | ||
kill server_process_test |
22 changes: 11 additions & 11 deletions
22
testdata/server_database.txt → cli/testdata/server_database.test.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
# Set a custom database path | ||
# set a custom database path | ||
env DATABASE_PATH=custom_relay.sqlite | ||
|
||
# Remove any existing custom database | ||
# remove any existing custom database | ||
rm -f $DATABASE_PATH | ||
|
||
# Add a license with a custom database path | ||
# add a license with a custom database path | ||
exec relay add --file license.lic --key 9E32DD-D8CC22-771926-C2D834-C506DC-V3 --public-key e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788 --database $DATABASE_PATH | ||
|
||
# Ensure that the custom database is created | ||
# ensure that the custom database is created | ||
exec test -f $DATABASE_PATH | ||
|
||
# Set a port as environment variable | ||
# set a port as environment variable | ||
env PORT=65010 | ||
|
||
# Start the server with custom database path | ||
# start the server with custom database path | ||
exec relay serve --port $PORT --database $DATABASE_PATH &server_process_test& | ||
|
||
# Wait for the server to start | ||
# wait for the server to start | ||
exec sleep 1 | ||
|
||
# Claim a license | ||
# claim a license | ||
exec curl -s -o response.txt -w "%{http_code}" -X PUT http://localhost:$PORT/v1/nodes/test_fingerprint | ||
|
||
# Expect a success response (status 201) | ||
# expect a success response (status 201) | ||
stdout '201' | ||
|
||
# Kill the process (stop the server) | ||
# kill the process (stop the server) | ||
kill server_process_test | ||
|
||
# Clean up the custom database | ||
# clean up the custom database | ||
rm -f $DATABASE_PATH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
package schema | ||
|
||
import _ "embed" | ||
import ( | ||
"embed" | ||
) | ||
|
||
//go:embed schema.sql | ||
var SchemaSQL string | ||
var Schema string | ||
|
||
//go:embed migrations/*.sql | ||
var Migrations embed.FS |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package db | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
|
||
"github.com/golang-migrate/migrate/v4" | ||
"github.com/golang-migrate/migrate/v4/database/sqlite3" | ||
"github.com/golang-migrate/migrate/v4/source" | ||
_ "github.com/mattn/go-sqlite3" | ||
) | ||
|
||
type Migrator struct { | ||
migrate *migrate.Migrate | ||
} | ||
|
||
func (m Migrator) Up() error { | ||
return m.migrate.Up() | ||
} | ||
|
||
func (m Migrator) Down() error { | ||
return m.migrate.Down() | ||
} | ||
|
||
func NewMigrator(db *sql.DB, migrations source.Driver) (*Migrator, error) { | ||
instance, err := sqlite3.WithInstance(db, &sqlite3.Config{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
m, err := migrate.NewWithInstance( | ||
"file", | ||
migrations, | ||
"sqlite3", | ||
instance, | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create migrator: %w", err) | ||
} | ||
|
||
return &Migrator{migrate: m}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.