From 5eeec274f93c00a0b997dfd099c889758e242928 Mon Sep 17 00:00:00 2001 From: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com> Date: Sun, 14 Apr 2024 01:42:57 +0530 Subject: [PATCH] feat: atlas and golang-migrate integration (#515) --- .github/scripts/check_if_migration_missed.sh | 14 + .github/workflows/db-migration.yml | 34 ++ atlas.hcl | 22 ++ generate_migration_records.sh | 33 ++ go.mod | 19 +- go.sum | 105 +++++- ssl_manager/constructor.go | 5 - swiftwave_service/cmd/db-migrate.go | 3 +- swiftwave_service/cmd/root.go | 3 +- swiftwave_service/core/migrate_database.go | 45 --- swiftwave_service/db/migrate_database.go | 57 +++ .../migrations/20240413191732_init.down.sql | 50 +++ .../db/migrations/20240413191732_init.up.sql | 329 ++++++++++++++++++ swiftwave_service/db/migrations/atlas.sum | 3 + swiftwave_service/db_models_loader/main.go | 44 +++ 15 files changed, 700 insertions(+), 66 deletions(-) create mode 100755 .github/scripts/check_if_migration_missed.sh create mode 100644 .github/workflows/db-migration.yml create mode 100644 atlas.hcl create mode 100755 generate_migration_records.sh delete mode 100644 swiftwave_service/core/migrate_database.go create mode 100644 swiftwave_service/db/migrate_database.go create mode 100644 swiftwave_service/db/migrations/20240413191732_init.down.sql create mode 100644 swiftwave_service/db/migrations/20240413191732_init.up.sql create mode 100644 swiftwave_service/db/migrations/atlas.sum create mode 100644 swiftwave_service/db_models_loader/main.go diff --git a/.github/scripts/check_if_migration_missed.sh b/.github/scripts/check_if_migration_missed.sh new file mode 100755 index 0000000000..df30cffca3 --- /dev/null +++ b/.github/scripts/check_if_migration_missed.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# get output of atlas migrate diff --env gorm +output=$(atlas migrate diff --env gorm --dev-url postgres://postgres:pass@localhost:5432/dev?sslmode=disable) + +# check if output contains `no changes to be made` +if echo "$output" | grep -q 'no changes to be made'; then + echo "No migration changes detected" + exit 0 +else + echo "Migration changes detected and need to be committed" + echo "Please run ./generate_migration_records.sh to generate new migration files" + exit 1 +fi \ No newline at end of file diff --git a/.github/workflows/db-migration.yml b/.github/workflows/db-migration.yml new file mode 100644 index 0000000000..8897e717eb --- /dev/null +++ b/.github/workflows/db-migration.yml @@ -0,0 +1,34 @@ +name: DB Migration +on: + [push, pull_request] +jobs: + check-uncommitted-db-migrations: + services: + # Spin up a postgres:15 container to be used as the dev-database. + postgres15: + image: postgres:15 + env: + POSTGRES_DB: dev + POSTGRES_PASSWORD: pass + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.22 + - name: Install atlas + uses: ariga/setup-atlas@master + - name: Install Dependencies + run: go mod download + - name: Check if migration is missed + run: ./.github/scripts/check_if_migration_missed.sh \ No newline at end of file diff --git a/atlas.hcl b/atlas.hcl new file mode 100644 index 0000000000..94f6cca604 --- /dev/null +++ b/atlas.hcl @@ -0,0 +1,22 @@ +data "external_schema" "gorm" { + program = [ + "go", + "run", + "-mod=mod", + "./swiftwave_service/db_models_loader", + ] +} + +env "gorm" { + src = data.external_schema.gorm.url + dev = "docker://postgres/15/dev" + migration { + dir = "file://swiftwave_service/db/migrations" + format = golang-migrate + } + format { + migrate { + diff = "{{ sql . \" \" }}" + } + } +} \ No newline at end of file diff --git a/generate_migration_records.sh b/generate_migration_records.sh new file mode 100755 index 0000000000..ea79d0ecab --- /dev/null +++ b/generate_migration_records.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env sh + +# join of all arguments from first to last using _ as separator +migration_name=$(echo "$@" | tr ' ' '_') + +# ask for the migration name +if [ -z "$migration_name" ]; then + read -p "Enter the migration name: " migration_name +fi + +# if the migration name is empty, exit +if [ -z "$migration_name" ]; then + echo "Migration name cannot be empty" + exit 1 +fi + +echo "Migration name: $migration_name" + +# anything except a-z0-9_ is not allowed +if echo "$migration_name" | grep -q '[^a-z0-9_]'; then + echo "Migration name can only contain lowercase alphabets, numbers, and underscores" + exit 1 +fi + +# check if atlas is installed +if ! command -v atlas > /dev/null; then + echo "atlas is not installed" + echo "Run \`curl -sSf https://atlasgo.sh | sh\` to install atlas or visit https://atlasgo.io/getting-started/ to learn more" + exit 1 +fi + +# create a new migration file +atlas migrate diff --env gorm $migration_name \ No newline at end of file diff --git a/go.mod b/go.mod index 756284eb33..839b009d50 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/swiftwave-org/swiftwave go 1.21.7 require ( + ariga.io/atlas-provider-gorm v0.3.2 github.com/99designs/gqlgen v0.17.45 github.com/aws/aws-sdk-go v1.51.21 github.com/docker/docker v26.0.1+incompatible @@ -10,6 +11,7 @@ require ( github.com/go-git/go-git/v5 v5.12.0 github.com/go-redis/redis/v8 v8.11.5 github.com/golang-jwt/jwt/v5 v5.2.1 + github.com/golang-migrate/migrate/v4 v4.17.0 github.com/hashicorp/go-set v0.1.14 github.com/labstack/echo-jwt/v4 v4.2.0 github.com/labstack/echo/v4 v4.11.4 @@ -57,7 +59,8 @@ require ( ) require ( - github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect + ariga.io/atlas-go-sdk v0.2.3 // indirect + github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect github.com/Microsoft/hcsshim v0.11.4 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/containerd/containerd v1.7.12 // indirect @@ -69,8 +72,13 @@ require ( github.com/go-logr/logr v1.4.1 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.2.6 // indirect + github.com/go-sql-driver/mysql v1.7.0 // indirect + github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect + github.com/golang-sql/sqlexp v0.1.0 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-cmp v0.6.0 // indirect + github.com/hashicorp/errwrap v1.1.0 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jackc/puddle/v2 v2.2.1 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect @@ -79,6 +87,8 @@ require ( github.com/klauspost/compress v1.16.7 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/magiconair/properties v1.8.7 // indirect + github.com/mattn/go-sqlite3 v1.14.17 // indirect + github.com/microsoft/go-mssqldb v1.6.0 // indirect github.com/moby/docker-image-spec v1.3.1 // indirect github.com/moby/patternmatcher v0.6.0 // indirect github.com/moby/sys/sequential v0.5.0 // indirect @@ -99,10 +109,13 @@ require ( go.uber.org/goleak v1.3.0 // indirect golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect golang.org/x/sync v0.6.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect - google.golang.org/grpc v1.58.3 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 // indirect + google.golang.org/grpc v1.59.0 // indirect google.golang.org/protobuf v1.33.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect + gorm.io/driver/mysql v1.5.1 // indirect + gorm.io/driver/sqlite v1.5.2 // indirect + gorm.io/driver/sqlserver v1.5.2 // indirect ) require ( diff --git a/go.sum b/go.sum index f9f8748ac7..7129f9b0ce 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,33 @@ +ariga.io/atlas-go-sdk v0.2.3 h1:DpKruiJ9ElJcNhYxnQM9ddzupHXEYFH0Jx6ZcZ7lKYQ= +ariga.io/atlas-go-sdk v0.2.3/go.mod h1:owkEEXw6jqne5KPVDfKsYB7cwMiMk3jtOiAAeKxS/yU= +ariga.io/atlas-provider-gorm v0.3.2 h1:Y3vQ9HPNQQTSwSAAGv0T/ESUjarHTjmvSg09ODGcaus= +ariga.io/atlas-provider-gorm v0.3.2/go.mod h1:NOXGkyHfWFm8vQO7T+je5Zj5DdLZhkzReXGfxnnK4VM= dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/99designs/gqlgen v0.17.45 h1:bH0AH67vIJo8JKNKPJP+pOPpQhZeuVRQLf53dKIpDik= github.com/99designs/gqlgen v0.17.45/go.mod h1:Bas0XQ+Jiu/Xm5E33jC8sES3G+iC2esHBMXcq0fUPs0= github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU= github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= -github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= -github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0/go.mod h1:ON4tFdPTwRcgWEaVDrN3584Ef+b7GgSJaXxe5fW9t4M= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.1 h1:/iHxaJhsFr0+xVFfbMr5vxz848jyiWuIEDhYq3y5odY= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.1/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 h1:vcYCAze6p19qBW7MhZybIsqD8sMV8js0NyQM8JDnVtg= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0/go.mod h1:OQeznEEkTZ9OrhHJoDD8ZDq51FHgXjqtP9z6bEwBq9U= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.1.2/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM= +github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.0 h1:yfJe15aSwEQ6Oo6J+gdfdulPNoZ3TEhmbhLIoxZcA+U= +github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.0/go.mod h1:Q28U+75mpCaSCDowNEmhIo/rmgdkqmkmzI7N6TGR4UY= +github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v0.8.0 h1:T028gtTPiYt/RMUfs8nVsAL7FDQrfLlrm/NnRG/zcC4= +github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v0.8.0/go.mod h1:cw4zVQgBby0Z5f2v0itn6se2dDP17nTjbZFXW5uPyHA= +github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= +github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= +github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.0 h1:HCc0+LpPfpCKs6LGGLAhwBARt9632unrVcI6i8s/8os= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.0/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= @@ -58,8 +80,12 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48 h1:fRzb/w+pyskVMQ+UbP35JkH8yB7MYb4q/qhBarqZE6g= github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= +github.com/dhui/dktest v0.4.0 h1:z05UmuXZHO/bgj/ds2bGMBu8FI4WA+Ag/m3ghL+om7M= +github.com/dhui/dktest v0.4.0/go.mod h1:v/Dbz1LgCBOi2Uki2nUqLBGa83hWBGFMu5MrgMDCc78= github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0= github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= +github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= +github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= github.com/docker/docker v26.0.1+incompatible h1:t39Hm6lpXuXtgkF0dm1t9a5HkbUfdGy6XbWexmGr+hA= github.com/docker/docker v26.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c= @@ -95,12 +121,23 @@ github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= +github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= +github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= +github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/golang-migrate/migrate/v4 v4.17.0 h1:rd40H3QXU0AA4IoLllFcEAEo9dYKRHYND2gB4p7xcaU= +github.com/golang-migrate/migrate/v4 v4.17.0/go.mod h1:+Cp2mtLP4/aXDTKb9wmXYitdrNx2HGs45rbWAo6OsKM= +github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA= +github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= +github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A= +github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= @@ -111,14 +148,24 @@ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= +github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms= github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= +github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/go-set v0.1.14 h1:ZU7JyS6QGueDuXYldjcuyKLR0XV14eOKcsQlGddXGgA= github.com/hashicorp/go-set v0.1.14/go.mod h1:FH9zJxnQYHPlZ7j9JaoQjZOFPBStOrelKOE11Wjwirc= +github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= @@ -133,6 +180,12 @@ github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= +github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs= +github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM= +github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo= +github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg= +github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs= +github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= @@ -154,6 +207,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/labstack/echo-jwt/v4 v4.2.0 h1:odSISV9JgcSCuhgQSV/6Io3i7nUmfM/QkBeR5GVJj5c= github.com/labstack/echo-jwt/v4 v4.2.0/go.mod h1:MA2RqdXdEn4/uEglx0HcUOgQSyBaTh5JcaHIan3biwU= github.com/labstack/echo/v4 v4.11.4 h1:vDZmA+qNeh1pd/cCkEicDMrjtrnMGQ1QFI9gWN1zGq8= @@ -171,8 +226,12 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM= +github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/mholt/acmez v1.2.0 h1:1hhLxSgY5FvH5HCnGUuwbKY2VQVo8IU7rxXKSnZ7F30= github.com/mholt/acmez v1.2.0/go.mod h1:VT9YwH1xgNX1kmYY89gY8xPJC84BFAisjo8Egigt4kE= +github.com/microsoft/go-mssqldb v1.6.0 h1:mM3gYdVwEPFrlg/Dvr2DNVEgYFG7L42l+dGc67NNNpc= +github.com/microsoft/go-mssqldb v1.6.0/go.mod h1:00mDtPbeQCRGC1HwOOR5K/gr30P1NcEG0vx6Kbv2aJU= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= @@ -185,6 +244,8 @@ github.com/moby/sys/user v0.1.0 h1:WmZ93f5Ux6het5iituh9x2zAG7NFY9Aqi49jjE1PaQg= github.com/moby/sys/user v0.1.0/go.mod h1:fKJhFOnsCN6xZ5gSfbM6zaHGgDJMrqt9/reuj4T7MmU= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= +github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= +github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= @@ -201,6 +262,8 @@ github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQ github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -242,6 +305,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= @@ -299,7 +364,10 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= +golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea h1:vLCWI/yYrdEHyN2JzIzPO3aaQJHQdp89IZBA/+azVC4= @@ -312,14 +380,19 @@ golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic= golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -339,6 +412,7 @@ golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -358,6 +432,8 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -367,6 +443,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= @@ -383,13 +461,13 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 h1:Z0hjGZePRE0ZBWotvtrwxFNrNE9CUAGtplaDK5NNI/g= -google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 h1:FmF5cCW94Ij59cfpoLiwTgodWmm60eEV0CjlsVg2fuw= -google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98/go.mod h1:rsr7RhLuwsDKL7RmgDDCUc6yaGr1iqceVb5Wv6f6YvQ= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 h1:bVf09lpb+OJbByTj913DRJioFFAjf/ZGxEz7MajTp2U= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= -google.golang.org/grpc v1.58.3 h1:BjnpXut1btbtgN/6sp+brB2Kbm2LjNXnidYujAVbSoQ= -google.golang.org/grpc v1.58.3/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= +google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b h1:+YaDE2r2OG8t/z5qmsh7Y+XXwCbvadxxZ0YY6mTdrVA= +google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b h1:CIC2YMXmIhYw6evmhPxBKJ4fmLbOFtXQN/GV3XOZR8k= +google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:IBQ646DjkDkvUIsVq/cc03FUFQ9wbZu7yE396YcL870= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 h1:AB/lmRny7e2pLhFEYIbl5qkDAUt2h0ZRO4wGPhZf+ik= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405/go.mod h1:67X1fPuzjcrkymZzZV1vvkFeTn2Rvc6lYF9MYFGCcwE= +google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk= +google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= @@ -403,6 +481,7 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= @@ -410,8 +489,16 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/driver/mysql v1.5.1 h1:WUEH5VF9obL/lTtzjmML/5e6VfFR/788coz2uaVCAZw= +gorm.io/driver/mysql v1.5.1/go.mod h1:Jo3Xu7mMhCyj8dlrb3WoCaRd1FhsVh+yMXb1jUInf5o= gorm.io/driver/postgres v1.5.7 h1:8ptbNJTDbEmhdr62uReG5BGkdQyeasu/FZHxI0IMGnM= gorm.io/driver/postgres v1.5.7/go.mod h1:3e019WlBaYI5o5LIdNV+LyxCMNtLOQETBXL2h4chKpA= +gorm.io/driver/sqlite v1.5.2 h1:TpQ+/dqCY4uCigCFyrfnrJnrW9zjpelWVoEVNy5qJkc= +gorm.io/driver/sqlite v1.5.2/go.mod h1:qxAuCol+2r6PannQDpOP1FP6ag3mKi4esLnB/jHed+4= +gorm.io/driver/sqlserver v1.5.2 h1:+o4RQ8w1ohPbADhFqDxeeZnSWjwOcBnxBckjTbcP4wk= +gorm.io/driver/sqlserver v1.5.2/go.mod h1:gaKF0MO0cfTq9Q3/XhkowSw4g6nIwHPGAs4hzKCmvBo= +gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= +gorm.io/gorm v1.25.2-0.20230610234218-206613868439/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= gorm.io/gorm v1.25.9 h1:wct0gxZIELDk8+ZqF/MVnHLkA1rvYlBWUMv2EdsK1g8= gorm.io/gorm v1.25.9/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= diff --git a/ssl_manager/constructor.go b/ssl_manager/constructor.go index ea3dfd6340..045e019079 100644 --- a/ssl_manager/constructor.go +++ b/ssl_manager/constructor.go @@ -18,11 +18,6 @@ func (s *Manager) Init(ctx context.Context, db gorm.DB, options ManagerOptions) s.ctx = ctx s.dbClient = db s.options = options - // Migrate database - err := db.AutoMigrate(&KeyAuthorizationToken{}) - if err != nil { - return errors.New("error while migrating database") - } // Initialize account acmeDirectory := "https://acme-staging-v02.api.letsencrypt.org/directory" if !options.IsStaging { diff --git a/swiftwave_service/cmd/db-migrate.go b/swiftwave_service/cmd/db-migrate.go index 26fe8bd963..e5d431720c 100644 --- a/swiftwave_service/cmd/db-migrate.go +++ b/swiftwave_service/cmd/db-migrate.go @@ -2,7 +2,6 @@ package cmd import ( "github.com/spf13/cobra" - swiftwave "github.com/swiftwave-org/swiftwave/swiftwave_service/core" "github.com/swiftwave-org/swiftwave/swiftwave_service/db" ) @@ -18,7 +17,7 @@ var dbMigrateCmd = &cobra.Command{ printError("Failed to create database client") } // Migrate the database - err = swiftwave.MigrateDatabase(client) + err = db.MigrateDatabase(client) if err != nil { printError("Failed to migrate the database") } else { diff --git a/swiftwave_service/cmd/root.go b/swiftwave_service/cmd/root.go index ef40e55323..5d889fc3b9 100644 --- a/swiftwave_service/cmd/root.go +++ b/swiftwave_service/cmd/root.go @@ -6,7 +6,6 @@ import ( swiftwave_config "github.com/swiftwave-org/swiftwave/swiftwave_service/config" "github.com/swiftwave-org/swiftwave/swiftwave_service/config/local_config" "github.com/swiftwave-org/swiftwave/swiftwave_service/config/system_config/bootstrap" - "github.com/swiftwave-org/swiftwave/swiftwave_service/core" "github.com/swiftwave-org/swiftwave/swiftwave_service/db" "os" @@ -81,7 +80,7 @@ func Execute() { printError("Failed to connect to database: " + err.Error()) os.Exit(1) } - err = core.MigrateDatabase(dbClient) + err = db.MigrateDatabase(dbClient) if err != nil { printError("Failed to migrate database: " + err.Error()) os.Exit(1) diff --git a/swiftwave_service/core/migrate_database.go b/swiftwave_service/core/migrate_database.go deleted file mode 100644 index b43d4d6f5f..0000000000 --- a/swiftwave_service/core/migrate_database.go +++ /dev/null @@ -1,45 +0,0 @@ -package core - -import ( - "errors" - SSL "github.com/swiftwave-org/swiftwave/ssl_manager" - "github.com/swiftwave-org/swiftwave/swiftwave_service/config/system_config" - "github.com/swiftwave-org/swiftwave/task_queue" - "gorm.io/gorm" - "log" -) - -func MigrateDatabase(dbClient *gorm.DB) error { - // Migrate the schema - err := dbClient.AutoMigrate( - &system_config.SystemConfig{}, - &Server{}, - &ServerLog{}, - &User{}, - &Domain{}, - &RedirectRule{}, - &PersistentVolume{}, - &Application{}, - &GitCredential{}, - &ImageRegistryCredential{}, - &IngressRule{}, - &EnvironmentVariable{}, - &PersistentVolumeBinding{}, - &Deployment{}, - &BuildArg{}, - &DeploymentLog{}, - &SSL.KeyAuthorizationToken{}, - &PersistentVolumeBackup{}, - &PersistentVolumeRestore{}, - &ConsoleToken{}, - &AnalyticsServiceToken{}, - &ServerResourceStat{}, - &ApplicationServiceResourceStat{}, - &task_queue.EnqueuedTask{}, - ) - if err != nil { - log.Println(err) - return errors.New("failed to migrate database \n" + err.Error()) - } - return nil -} diff --git a/swiftwave_service/db/migrate_database.go b/swiftwave_service/db/migrate_database.go new file mode 100644 index 0000000000..841e0827b0 --- /dev/null +++ b/swiftwave_service/db/migrate_database.go @@ -0,0 +1,57 @@ +package db + +import ( + "embed" + "errors" + "github.com/golang-migrate/migrate/v4" + "github.com/golang-migrate/migrate/v4/database/postgres" + _ "github.com/golang-migrate/migrate/v4/source/file" + "github.com/golang-migrate/migrate/v4/source/iofs" + "github.com/swiftwave-org/swiftwave/swiftwave_service/logger" + "gorm.io/gorm" +) + +//go:embed all:migrations +var migrationFilesFS embed.FS + +func MigrateDatabase(client *gorm.DB) error { + migrationFSDriver, err := iofs.New(migrationFilesFS, "migrations") + if err != nil { + logger.DatabaseLoggerError.Println("Failed to create migration fs driver") + logger.DatabaseLoggerError.Println(err) + return errors.New("unable to parse migration files") + } + // Create db connection + sqlDb, err := client.DB() + if err != nil { + logger.DatabaseLoggerError.Println("Failed to create migrate instance") + logger.DatabaseLoggerError.Println(err) + return errors.New("failed to migrate database") + } + driver, err := postgres.WithInstance(sqlDb, &postgres.Config{}) + if err != nil { + logger.DatabaseLoggerError.Println("Failed to create migrate instance") + logger.DatabaseLoggerError.Println(err) + return errors.New("failed to migrate database") + } + m, err := migrate.NewWithInstance( + "iofs", + migrationFSDriver, + "postgres", driver) + if err != nil { + logger.DatabaseLoggerError.Println("Failed to create migrate instance") + logger.DatabaseLoggerError.Println(err) + return errors.New("failed to migrate database") + } + err = m.Up() + if err != nil { + if errors.Is(err, migrate.ErrNoChange) { + logger.DatabaseLogger.Println("No change in database schema") + return nil + } + logger.DatabaseLoggerError.Println("Failed to migrate database") + logger.DatabaseLoggerError.Println(err) + return errors.New("failed to migrate database") + } + return nil +} diff --git a/swiftwave_service/db/migrations/20240413191732_init.down.sql b/swiftwave_service/db/migrations/20240413191732_init.down.sql new file mode 100644 index 0000000000..4948801489 --- /dev/null +++ b/swiftwave_service/db/migrations/20240413191732_init.down.sql @@ -0,0 +1,50 @@ +-- reverse: create "server_resource_stats" table +DROP TABLE "public"."server_resource_stats"; +-- reverse: create index "idx_server_logs_deleted_at" to table: "server_logs" +DROP INDEX "public"."idx_server_logs_deleted_at"; +-- reverse: create "server_logs" table +DROP TABLE "public"."server_logs"; +-- reverse: create "redirect_rules" table +DROP TABLE "public"."redirect_rules"; +-- reverse: create "persistent_volume_restores" table +DROP TABLE "public"."persistent_volume_restores"; +-- reverse: create "persistent_volume_bindings" table +DROP TABLE "public"."persistent_volume_bindings"; +-- reverse: create "persistent_volume_backups" table +DROP TABLE "public"."persistent_volume_backups"; +-- reverse: create "persistent_volumes" table +DROP TABLE "public"."persistent_volumes"; +-- reverse: create "ingress_rules" table +DROP TABLE "public"."ingress_rules"; +-- reverse: create "domains" table +DROP TABLE "public"."domains"; +-- reverse: create "environment_variables" table +DROP TABLE "public"."environment_variables"; +-- reverse: create "deployment_logs" table +DROP TABLE "public"."deployment_logs"; +-- reverse: create "console_tokens" table +DROP TABLE "public"."console_tokens"; +-- reverse: create "build_args" table +DROP TABLE "public"."build_args"; +-- reverse: create "deployments" table +DROP TABLE "public"."deployments"; +-- reverse: create "image_registry_credentials" table +DROP TABLE "public"."image_registry_credentials"; +-- reverse: create "git_credentials" table +DROP TABLE "public"."git_credentials"; +-- reverse: create "application_service_resource_stats" table +DROP TABLE "public"."application_service_resource_stats"; +-- reverse: create "applications" table +DROP TABLE "public"."applications"; +-- reverse: create "analytics_service_tokens" table +DROP TABLE "public"."analytics_service_tokens"; +-- reverse: create "servers" table +DROP TABLE "public"."servers"; +-- reverse: create "key_authorization_tokens" table +DROP TABLE "public"."key_authorization_tokens"; +-- reverse: create "users" table +DROP TABLE "public"."users"; +-- reverse: create "system_configs" table +DROP TABLE "public"."system_configs"; +-- reverse: create "enqueued_tasks" table +DROP TABLE "public"."enqueued_tasks"; diff --git a/swiftwave_service/db/migrations/20240413191732_init.up.sql b/swiftwave_service/db/migrations/20240413191732_init.up.sql new file mode 100644 index 0000000000..b17fc8e86f --- /dev/null +++ b/swiftwave_service/db/migrations/20240413191732_init.up.sql @@ -0,0 +1,329 @@ +-- create "enqueued_tasks" table +CREATE TABLE "public"."enqueued_tasks" ( + "id" bigserial NOT NULL, + "queue_name" text NULL, + "body" text NULL, + "hash" text NULL, + PRIMARY KEY ("id") +); +-- create "system_configs" table +CREATE TABLE "public"."system_configs" ( + "id" bigserial NOT NULL, + "config_version" bigint NULL DEFAULT 1, + "network_name" text NULL, + "restricted_ports" integer[] NULL, + "jwt_secret_key" text NULL, + "ssh_private_key" text NULL, + "lets_encrypt_config_id" bigserial NOT NULL, + "lets_encrypt_config_staging" boolean NULL DEFAULT false, + "lets_encrypt_config_email_id" text NULL, + "lets_encrypt_config_private_key" text NULL, + "haproxy_config_image" text NULL, + "haproxy_config_username" text NULL, + "haproxy_config_password" text NULL, + "udp_proxy_config_image" text NULL, + "persistent_volume_backup_config_s3_backup_enabled" boolean NULL, + "persistent_volume_backup_config_s3_backup_endpoint" text NULL, + "persistent_volume_backup_config_s3_backup_region" text NULL, + "persistent_volume_backup_config_s3_backup_bucket" text NULL, + "persistent_volume_backup_config_s3_backup_access_key_id" text NULL, + "persistent_volume_backup_config_s3_backup_secret_access_key" text NULL, + "persistent_volume_backup_config_s3_backup_force_path_style" boolean NULL, + "pub_sub_config_mode" text NULL DEFAULT 'local', + "pub_sub_config_buffer_length" bigint NULL DEFAULT 2000, + "pub_sub_config_redis_host" text NULL, + "pub_sub_config_redis_port" bigint NULL, + "pub_sub_config_redis_password" text NULL, + "pub_sub_config_redis_database_id" bigint NULL, + "task_queue_config_mode" text NULL DEFAULT 'local', + "task_queue_config_remote_task_queue_type" text NULL DEFAULT 'none', + "task_queue_config_max_outstanding_messages_per_queue" bigint NULL DEFAULT 2, + "task_queue_config_no_of_workers_per_queue" bigint NULL, + "task_queue_config_amqp_protocol" text NULL, + "task_queue_config_amqp_host" text NULL, + "task_queue_config_amqp_port" bigint NULL, + "task_queue_config_amqp_user" text NULL, + "task_queue_config_amqp_password" text NULL, + "task_queue_config_amqp_v_host" text NULL, + "task_queue_config_redis_host" text NULL, + "task_queue_config_redis_port" bigint NULL, + "task_queue_config_redis_password" text NULL, + "task_queue_config_redis_database_id" bigint NULL, + "image_registry_config_endpoint" text NULL, + "image_registry_config_username" text NULL, + "image_registry_config_password" text NULL, + "image_registry_config_namespace" text NULL, + PRIMARY KEY ("id", "lets_encrypt_config_id") +); +-- create "users" table +CREATE TABLE "public"."users" ( + "id" bigserial NOT NULL, + "username" text NULL, + "role" text NULL DEFAULT 'user', + "password_hash" text NULL, + PRIMARY KEY ("id"), + CONSTRAINT "uni_users_username" UNIQUE ("username") +); +-- create "key_authorization_tokens" table +CREATE TABLE "public"."key_authorization_tokens" ( + "token" text NOT NULL, + "authorization_token" text NULL, + PRIMARY KEY ("token") +); +-- create "servers" table +CREATE TABLE "public"."servers" ( + "id" bigserial NOT NULL, + "ip" text NULL, + "host_name" text NULL, + "user" text NULL, + "ssh_port" bigint NULL DEFAULT 22, + "schedule_deployments" boolean NULL DEFAULT true, + "docker_unix_socket_path" text NULL, + "swarm_mode" text NULL, + "proxy_enabled" boolean NULL DEFAULT false, + "proxy_setup_running" boolean NULL DEFAULT false, + "proxy_type" text NULL DEFAULT 'active', + "status" text NULL, + "last_ping" timestamptz NULL, + PRIMARY KEY ("id"), + CONSTRAINT "uni_servers_host_name" UNIQUE ("host_name") +); +-- create "analytics_service_tokens" table +CREATE TABLE "public"."analytics_service_tokens" ( + "id" text NOT NULL, + "token" text NULL, + "server_id" bigint NULL, + "created_at" timestamptz NULL, + PRIMARY KEY ("id"), + CONSTRAINT "uni_analytics_service_tokens_token" UNIQUE ("token"), + CONSTRAINT "fk_servers_analytics_service_token" FOREIGN KEY ("server_id") REFERENCES "public"."servers" ("id") ON UPDATE CASCADE ON DELETE CASCADE +); +-- create "applications" table +CREATE TABLE "public"."applications" ( + "id" text NOT NULL, + "name" text NULL, + "deployment_mode" text NULL, + "replicas" bigint NULL, + "command" text NULL, + "capabilities" text[] NULL, + "sysctls" text[] NULL, + "is_deleted" boolean NULL DEFAULT false, + "webhook_token" text NULL, + "is_sleeping" boolean NULL DEFAULT false, + "application_group" text NULL, + PRIMARY KEY ("id"), + CONSTRAINT "uni_applications_name" UNIQUE ("name") +); +-- create "application_service_resource_stats" table +CREATE TABLE "public"."application_service_resource_stats" ( + "id" bigserial NOT NULL, + "application_id" text NULL, + "cpu_usage_percent" smallint NULL, + "reporting_server_count" bigint NULL, + "used_memory_mb" bigint NULL, + "network_sent_kb" bigint NULL, + "network_recv_kb" bigint NULL, + "network_sent_kbps" bigint NULL, + "network_recv_kbps" bigint NULL, + "recorded_at" timestamptz NULL, + PRIMARY KEY ("id"), + CONSTRAINT "fk_applications_resource_stats" FOREIGN KEY ("application_id") REFERENCES "public"."applications" ("id") ON UPDATE CASCADE ON DELETE CASCADE +); +-- create "git_credentials" table +CREATE TABLE "public"."git_credentials" ( + "id" bigserial NOT NULL, + "name" text NULL, + "username" text NULL, + "password" text NULL, + PRIMARY KEY ("id") +); +-- create "image_registry_credentials" table +CREATE TABLE "public"."image_registry_credentials" ( + "id" bigserial NOT NULL, + "url" text NULL, + "username" text NULL, + "password" text NULL, + PRIMARY KEY ("id") +); +-- create "deployments" table +CREATE TABLE "public"."deployments" ( + "id" text NOT NULL, + "application_id" text NULL, + "upstream_type" text NULL, + "git_credential_id" bigint NULL, + "git_provider" text NULL, + "repository_owner" text NULL, + "repository_name" text NULL, + "repository_branch" text NULL, + "code_path" text NULL, + "commit_hash" text NULL, + "source_code_compressed_file_name" text NULL, + "docker_image" text NULL, + "image_registry_credential_id" bigint NULL, + "dockerfile" text NULL, + "status" text NULL, + "created_at" timestamptz NULL, + PRIMARY KEY ("id"), + CONSTRAINT "fk_applications_deployments" FOREIGN KEY ("application_id") REFERENCES "public"."applications" ("id") ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT "fk_applications_latest_deployment" FOREIGN KEY ("application_id") REFERENCES "public"."applications" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_git_credentials_deployments" FOREIGN KEY ("git_credential_id") REFERENCES "public"."git_credentials" ("id") ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT "fk_image_registry_credentials_deployments" FOREIGN KEY ("image_registry_credential_id") REFERENCES "public"."image_registry_credentials" ("id") ON UPDATE CASCADE ON DELETE CASCADE +); +-- create "build_args" table +CREATE TABLE "public"."build_args" ( + "id" bigserial NOT NULL, + "deployment_id" text NULL, + "key" text NULL, + "value" text NULL, + PRIMARY KEY ("id"), + CONSTRAINT "fk_deployments_build_args" FOREIGN KEY ("deployment_id") REFERENCES "public"."deployments" ("id") ON UPDATE CASCADE ON DELETE CASCADE +); +-- create "console_tokens" table +CREATE TABLE "public"."console_tokens" ( + "id" text NOT NULL, + "target" text NULL, + "server_id" bigint NULL, + "application_id" text NULL, + "token" text NULL, + "expires_at" timestamptz NULL, + PRIMARY KEY ("id"), + CONSTRAINT "uni_console_tokens_token" UNIQUE ("token"), + CONSTRAINT "fk_applications_console_tokens" FOREIGN KEY ("application_id") REFERENCES "public"."applications" ("id") ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT "fk_servers_console_tokens" FOREIGN KEY ("server_id") REFERENCES "public"."servers" ("id") ON UPDATE CASCADE ON DELETE CASCADE +); +-- create "deployment_logs" table +CREATE TABLE "public"."deployment_logs" ( + "id" bigserial NOT NULL, + "deployment_id" text NULL, + "content" text NULL, + "created_at" timestamptz NULL, + PRIMARY KEY ("id"), + CONSTRAINT "fk_deployments_logs" FOREIGN KEY ("deployment_id") REFERENCES "public"."deployments" ("id") ON UPDATE CASCADE ON DELETE CASCADE +); +-- create "environment_variables" table +CREATE TABLE "public"."environment_variables" ( + "id" bigserial NOT NULL, + "application_id" text NULL, + "key" text NULL, + "value" text NULL, + PRIMARY KEY ("id"), + CONSTRAINT "fk_applications_environment_variables" FOREIGN KEY ("application_id") REFERENCES "public"."applications" ("id") ON UPDATE CASCADE ON DELETE CASCADE +); +-- create "domains" table +CREATE TABLE "public"."domains" ( + "id" bigserial NOT NULL, + "name" text NULL, + "ssl_status" text NULL, + "ssl_private_key" text NULL, + "ssl_full_chain" text NULL, + "ssl_issued_at" timestamptz NULL, + "ssl_expired_at" timestamptz NULL, + "ssl_issuer" text NULL, + "s_slauto_renew" boolean NULL DEFAULT false, + PRIMARY KEY ("id"), + CONSTRAINT "uni_domains_name" UNIQUE ("name") +); +-- create "ingress_rules" table +CREATE TABLE "public"."ingress_rules" ( + "id" bigserial NOT NULL, + "domain_id" bigint NULL, + "application_id" text NULL, + "protocol" text NULL, + "port" bigint NULL, + "target_port" bigint NULL, + "status" text NULL, + "created_at" timestamptz NULL, + "updated_at" timestamptz NULL, + PRIMARY KEY ("id"), + CONSTRAINT "fk_applications_ingress_rules" FOREIGN KEY ("application_id") REFERENCES "public"."applications" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_domains_ingress_rules" FOREIGN KEY ("domain_id") REFERENCES "public"."domains" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- create "persistent_volumes" table +CREATE TABLE "public"."persistent_volumes" ( + "id" bigserial NOT NULL, + "name" text NULL, + "type" text NULL DEFAULT 'local', + "nfs_config_host" text NULL, + "nfs_config_path" text NULL, + "nfs_config_version" bigint NULL, + PRIMARY KEY ("id"), + CONSTRAINT "uni_persistent_volumes_name" UNIQUE ("name") +); +-- create "persistent_volume_backups" table +CREATE TABLE "public"."persistent_volume_backups" ( + "id" bigserial NOT NULL, + "type" text NULL, + "status" text NULL, + "file" text NULL, + "file_size_mb" numeric NULL, + "persistent_volume_id" bigint NULL, + "created_at" timestamptz NULL, + "completed_at" timestamptz NULL, + PRIMARY KEY ("id"), + CONSTRAINT "fk_persistent_volumes_persistent_volume_backups" FOREIGN KEY ("persistent_volume_id") REFERENCES "public"."persistent_volumes" ("id") ON UPDATE CASCADE ON DELETE CASCADE +); +-- create "persistent_volume_bindings" table +CREATE TABLE "public"."persistent_volume_bindings" ( + "id" bigserial NOT NULL, + "application_id" text NULL, + "persistent_volume_id" bigint NULL, + "mounting_path" text NULL, + PRIMARY KEY ("id"), + CONSTRAINT "fk_applications_persistent_volume_bindings" FOREIGN KEY ("application_id") REFERENCES "public"."applications" ("id") ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT "fk_persistent_volumes_persistent_volume_bindings" FOREIGN KEY ("persistent_volume_id") REFERENCES "public"."persistent_volumes" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- create "persistent_volume_restores" table +CREATE TABLE "public"."persistent_volume_restores" ( + "id" bigserial NOT NULL, + "type" text NULL, + "file" text NULL, + "status" text NULL, + "persistent_volume_id" bigint NULL, + "created_at" timestamptz NULL, + "completed_at" timestamptz NULL, + PRIMARY KEY ("id"), + CONSTRAINT "fk_persistent_volumes_persistent_volume_restores" FOREIGN KEY ("persistent_volume_id") REFERENCES "public"."persistent_volumes" ("id") ON UPDATE CASCADE ON DELETE CASCADE +); +-- create "redirect_rules" table +CREATE TABLE "public"."redirect_rules" ( + "id" bigserial NOT NULL, + "domain_id" bigint NULL, + "protocol" text NULL, + "redirect_url" text NULL, + "status" text NULL, + "created_at" timestamptz NULL, + "updated_at" timestamptz NULL, + PRIMARY KEY ("id"), + CONSTRAINT "fk_domains_redirect_rules" FOREIGN KEY ("domain_id") REFERENCES "public"."domains" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- create "server_logs" table +CREATE TABLE "public"."server_logs" ( + "id" bigserial NOT NULL, + "created_at" timestamptz NULL, + "updated_at" timestamptz NULL, + "deleted_at" timestamptz NULL, + "server_id" bigint NULL, + "title" text NULL, + "content" text NULL, + PRIMARY KEY ("id"), + CONSTRAINT "fk_servers_logs" FOREIGN KEY ("server_id") REFERENCES "public"."servers" ("id") ON UPDATE CASCADE ON DELETE CASCADE +); +-- create index "idx_server_logs_deleted_at" to table: "server_logs" +CREATE INDEX "idx_server_logs_deleted_at" ON "public"."server_logs" ("deleted_at"); +-- create "server_resource_stats" table +CREATE TABLE "public"."server_resource_stats" ( + "id" bigserial NOT NULL, + "server_id" bigint NULL, + "cpu_usage_percent" smallint NULL, + "memory_total_gb" numeric NULL, + "memory_used_gb" numeric NULL, + "memory_cached_gb" numeric NULL, + "disk_stats" bytea NULL, + "network_sent_kb" bigint NULL, + "network_recv_kb" bigint NULL, + "network_sent_kbps" bigint NULL, + "network_recv_kbps" bigint NULL, + "recorded_at" timestamptz NULL, + PRIMARY KEY ("id"), + CONSTRAINT "fk_servers_resource_stats" FOREIGN KEY ("server_id") REFERENCES "public"."servers" ("id") ON UPDATE CASCADE ON DELETE CASCADE +); diff --git a/swiftwave_service/db/migrations/atlas.sum b/swiftwave_service/db/migrations/atlas.sum new file mode 100644 index 0000000000..c7984807be --- /dev/null +++ b/swiftwave_service/db/migrations/atlas.sum @@ -0,0 +1,3 @@ +h1:VF+tZx4laXZ3T2EmA16xC0WOdD8kyupvVhIxHyzqhow= +20240413191732_init.down.sql h1:HoitObGwuKF/akF4qg3dol2FfNTLCEuf6wHYDuCez8I= +20240413191732_init.up.sql h1:SSfeL4XTzfkPhdTfo6ElhmZCvlDvESyB4ZLqJbvMkM0= diff --git a/swiftwave_service/db_models_loader/main.go b/swiftwave_service/db_models_loader/main.go new file mode 100644 index 0000000000..0931e7f007 --- /dev/null +++ b/swiftwave_service/db_models_loader/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "ariga.io/atlas-provider-gorm/gormschema" + "fmt" + SSL "github.com/swiftwave-org/swiftwave/ssl_manager" + "github.com/swiftwave-org/swiftwave/swiftwave_service/config/system_config" + "github.com/swiftwave-org/swiftwave/swiftwave_service/core" + "github.com/swiftwave-org/swiftwave/task_queue" + "io" + "os" +) + +func main() { + stmts, err := gormschema.New("postgres").Load(&system_config.SystemConfig{}, + &core.Server{}, + &core.ServerLog{}, + &core.User{}, + &core.Domain{}, + &core.RedirectRule{}, + &core.PersistentVolume{}, + &core.Application{}, + &core.GitCredential{}, + &core.ImageRegistryCredential{}, + &core.IngressRule{}, + &core.EnvironmentVariable{}, + &core.PersistentVolumeBinding{}, + &core.Deployment{}, + &core.BuildArg{}, + &core.DeploymentLog{}, + &SSL.KeyAuthorizationToken{}, + &core.PersistentVolumeBackup{}, + &core.PersistentVolumeRestore{}, + &core.ConsoleToken{}, + &core.AnalyticsServiceToken{}, + &core.ServerResourceStat{}, + &core.ApplicationServiceResourceStat{}, + &task_queue.EnqueuedTask{}) + if err != nil { + _, _ = fmt.Fprintf(os.Stderr, "failed to load gorm schema: %v\n", err) + os.Exit(1) + } + _, _ = io.WriteString(os.Stdout, stmts) +}