1
0
mirror of https://github.com/raseels-repos/golang-saas-starter-kit.git synced 2025-08-08 22:36:41 +02:00

fix schema migration requiring web context

This commit is contained in:
Lee Brown
2019-08-21 19:28:23 -08:00
parent 9e0f105e2f
commit 4894f2a3d8
14 changed files with 79 additions and 76 deletions

View File

@ -9,6 +9,7 @@ import (
"path/filepath"
"strings"
"geeks-accelerator/oss/saas-starter-kit/internal/schema"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/cloudfront"
@ -18,7 +19,6 @@ import (
"github.com/iancoleman/strcase"
"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
"geeks-accelerator/oss/saas-starter-kit/internal/schema"
"gitlab.com/geeks-accelerator/oss/devops/pkg/devdeploy"
)
@ -35,7 +35,7 @@ type Env = string
var (
EnvDev Env = webcontext.Env_Dev
EnvStage Env = webcontext.Env_Stage
EnvStage Env = webcontext.Env_Stage
EnvProd Env = webcontext.Env_Prod
)

View File

@ -14,8 +14,8 @@ import (
type Function = string
var (
Function_Ddlogscollector = "ddlogscollector"
Function_YourNewFunction = "your-new-function"
Function_Ddlogscollector = "ddlogscollector"
Function_YourNewFunction = "your-new-function"
)
// List of function names used by main.go for help.

View File

@ -4,13 +4,13 @@ import (
"context"
"log"
"geeks-accelerator/oss/saas-starter-kit/internal/schema"
"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
"geeks-accelerator/oss/saas-starter-kit/internal/schema"
"gitlab.com/geeks-accelerator/oss/devops/pkg/devdeploy"
)
// RunSchemaMigrationsForTargetEnv executes the build commands for a target service.
// RunSchemaMigrationsForTargetEnv executes schema migrations for the target environment.
func RunSchemaMigrationsForTargetEnv(log *log.Logger, awsCredentials devdeploy.AwsCredentials, targetEnv Env, isUnittest bool) error {
cfgCtx, err := NewConfigContext(targetEnv, awsCredentials)
@ -34,5 +34,5 @@ func RunSchemaMigrationsForTargetEnv(log *log.Logger, awsCredentials devdeploy.A
}
defer masterDb.Close()
return schema.Migrate(context.Background(), masterDb, log, false)
return schema.Migrate(context.Background(), targetEnv, masterDb, log, false)
}

View File

@ -8,10 +8,10 @@ import (
"path/filepath"
"strings"
"github.com/pkg/errors"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/iancoleman/strcase"
"github.com/pkg/errors"
"gitlab.com/geeks-accelerator/oss/devops/pkg/devdeploy"
"gopkg.in/go-playground/validator.v9"
)
@ -33,12 +33,12 @@ var ServiceNames = []Service{
// ServiceConfig defines the settings for a service.
type ServiceConfig struct {
// Required flags.
Name string `validate:"required" example:"web-api"`
ServiceHostPrimary string `validate:"required" example:"example-project.com"`
DesiredCount int `validate:"required" example:"2"`
ServiceDir string `validate:"required"`
Dockerfile string `validate:"required" example:"./cmd/web-api/Dockerfile"`
ReleaseTag string `validate:"required"`
Name string `validate:"required" example:"web-api"`
ServiceHostPrimary string `validate:"required" example:"example-project.com"`
DesiredCount int `validate:"required" example:"2"`
ServiceDir string `validate:"required"`
Dockerfile string `validate:"required" example:"./cmd/web-api/Dockerfile"`
ReleaseTag string `validate:"required"`
// Optional flags.
ServiceHostNames []string `validate:"omitempty" example:"subdomain.example-project.com"`
@ -89,7 +89,7 @@ func NewServiceConfig(serviceName string, cfg *devdeploy.Config) (ServiceConfig,
// Set the hostnames for the service.
if cfg.Env == EnvProd {
srv.ServiceHostPrimary = "example.saasstartupkit.com"
srv.ServiceHostPrimary = "example.saasstartupkit.com"
// Any hostname listed here that doesn't match the primary hostname will be updated in Route 53 but the
// service itself will redirect any requests back to the primary hostname.
@ -97,7 +97,7 @@ func NewServiceConfig(serviceName string, cfg *devdeploy.Config) (ServiceConfig,
fmt.Sprintf("%s.example.saasstartupkit.com", cfg.Env),
}
} else {
srv.ServiceHostPrimary = fmt.Sprintf("%s.example.saasstartupkit.com", cfg.Env)
srv.ServiceHostPrimary = fmt.Sprintf("%s.example.saasstartupkit.com", cfg.Env)
}
case ServiceWebApi:
@ -111,8 +111,8 @@ func NewServiceConfig(serviceName string, cfg *devdeploy.Config) (ServiceConfig,
default:
return ServiceConfig{}, errors.Wrapf(devdeploy.ErrInvalidService,
"No service config defined for service '%s'",
serviceName)
"No service config defined for service '%s'",
serviceName)
}
// Set the docker file if no custom one has been defined for the service.
@ -140,7 +140,6 @@ func (c ServiceConfig) BaseUrl() string {
return fmt.Sprintf("%s://%s/", schema, c.ServiceHostPrimary)
}
// NewServiceContext returns the ServiceContext for a service that is configured for the target deployment env.
func NewServiceContext(serviceName Service, cfg *devdeploy.Config) (*ServiceContext, error) {
@ -193,7 +192,6 @@ func NewServiceContext(serviceName Service, cfg *devdeploy.Config) (*ServiceCont
}
}
// =========================================================================
// Service dependant settings.
@ -306,7 +304,6 @@ func NewServiceContext(serviceName Service, cfg *devdeploy.Config) (*ServiceCont
return def, nil
}
// Define the ServiceContext for the web-api that will be used for build and deploy.
case ServiceWebApi: