diff --git a/.github/workflows/check_pr_title.yml.yml b/.github/workflows/check_pr_title.yml.yml new file mode 100644 index 000000000..45e2b2f48 --- /dev/null +++ b/.github/workflows/check_pr_title.yml.yml @@ -0,0 +1,8 @@ +name: Check PR Title +on: + pull_request: +jobs: + check: + uses: goravel/.github/.github/workflows/check_pr_title.yml@master + secrets: inherit + \ No newline at end of file diff --git a/.github/workflows/pr-check-title.yml b/.github/workflows/pr-check-title.yml deleted file mode 100644 index e2c9a36e3..000000000 --- a/.github/workflows/pr-check-title.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: PR Check Title -on: - pull_request: -jobs: - pr-check-title: - runs-on: ubuntu-latest - steps: - - uses: Slashgear/action-check-pr-title@v4.3.0 - with: - regexp: "^(feat|fix|docs|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release|revert)(\\(.+\\))?!?: .+" - helpMessage: "Your PR title is invalid. Please follow the Conventional Commits specification: https://www.conventionalcommits.org/en/v1.0.0/" diff --git a/.github/workflows/test_external.yml b/.github/workflows/test_external.yml new file mode 100644 index 000000000..0f7be0e59 --- /dev/null +++ b/.github/workflows/test_external.yml @@ -0,0 +1,22 @@ +name: Test External +on: + push: + branches: + - master + pull_request: +jobs: + ubuntu: + strategy: + matrix: + go: [ "1.22", "1.23" ] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go }} + - name: Install dependencies + run: go mod tidy + - name: Run tests + run: cd tests && go test -timeout 1h ./... + \ No newline at end of file diff --git a/contracts/database/driver/driver.go b/contracts/database/driver/driver.go index 37890c5f7..fa1ff10fa 100644 --- a/contracts/database/driver/driver.go +++ b/contracts/database/driver/driver.go @@ -2,6 +2,7 @@ package driver import ( "gorm.io/gorm" + "gorm.io/gorm/clause" "github.com/goravel/framework/contracts/database" "github.com/goravel/framework/contracts/database/orm" @@ -12,8 +13,14 @@ import ( type Driver interface { Config() database.Config Docker() (testing.DatabaseDriver, error) - Gorm() (*gorm.DB, error) + Gorm() (*gorm.DB, GormQuery, error) Grammar() schema.Grammar Processor() schema.Processor Schema(orm.Orm) schema.DriverSchema } + +type GormQuery interface { + LockForUpdate() clause.Expression + RandomOrder() string + SharedLock() clause.Expression +} diff --git a/contracts/database/orm/orm.go b/contracts/database/orm/orm.go index 6df0c3fd1..bb332de9c 100644 --- a/contracts/database/orm/orm.go +++ b/contracts/database/orm/orm.go @@ -3,8 +3,6 @@ package orm import ( "context" "database/sql" - - "github.com/goravel/framework/contracts/database" ) type Orm interface { @@ -52,7 +50,7 @@ type Query interface { // Distinct specifies distinct fields to query. Distinct(args ...any) Query // Driver gets the driver for the query. - Driver() database.Driver + Driver() string // Exec executes raw sql Exec(sql string, values ...any) (*Result, error) // Exists returns true if matching records exist; otherwise, it returns false. diff --git a/database/console/show_command.go b/database/console/show_command.go index 0a6a5784b..786c81391 100644 --- a/database/console/show_command.go +++ b/database/console/show_command.go @@ -106,35 +106,34 @@ func (r *ShowCommand) Handle(ctx console.Context) error { func (r *ShowCommand) getDataBaseInfo() (name, version, openConnections string, err error) { var ( - drivers = map[database.Driver]struct { + drivers = map[string]struct { name string versionQuery string openConnectionsQuery string }{ - database.DriverSqlite: { + database.DriverSqlite.String(): { name: "SQLite", versionQuery: "SELECT sqlite_version() AS value;", }, - database.DriverMysql: { + database.DriverMysql.String(): { name: "MySQL", versionQuery: "SELECT VERSION() AS value;", openConnectionsQuery: "SHOW status WHERE variable_name = 'threads_connected';", }, - database.DriverPostgres: { + database.DriverPostgres.String(): { name: "PostgresSQL", versionQuery: "SELECT current_setting('server_version') AS value;", openConnectionsQuery: "SELECT COUNT(*) AS value FROM pg_stat_activity;", }, - database.DriverSqlserver: { + database.DriverSqlserver.String(): { name: "SQL Server", versionQuery: "SELECT SERVERPROPERTY('productversion') AS value;", openConnectionsQuery: "SELECT COUNT(*) Value FROM sys.dm_exec_sessions WHERE status = 'running';", }, } ) - name = string(r.schema.Orm().Query().Driver()) - if driver, ok := drivers[r.schema.Orm().Query().Driver()]; ok { - name = driver.name + name = r.schema.Orm().Query().Driver() + if driver, ok := drivers[name]; ok { var versionResult queryResult if err = r.schema.Orm().Query().Raw(driver.versionQuery).Scan(&versionResult); err == nil { version = versionResult.Value diff --git a/database/console/show_command_test.go b/database/console/show_command_test.go index 658466c4c..7837964cb 100644 --- a/database/console/show_command_test.go +++ b/database/console/show_command_test.go @@ -5,7 +5,6 @@ import ( "github.com/stretchr/testify/assert" - "github.com/goravel/framework/contracts/database" "github.com/goravel/framework/contracts/database/schema" mocksconfig "github.com/goravel/framework/mocks/config" mocksconsole "github.com/goravel/framework/mocks/console" @@ -65,9 +64,9 @@ func TestShowCommand(t *testing.T) { mockConfig.EXPECT().GetString("database.connections.test.host").Return("host").Once() mockConfig.EXPECT().GetString("database.connections.test.port").Return("port").Once() mockConfig.EXPECT().GetString("database.connections.test.username").Return("username").Once() - mockQuery.EXPECT().Driver().Return(database.DriverMysql).Twice() - mockOrm.EXPECT().Query().Return(mockQuery).Times(4) - mockSchema.EXPECT().Orm().Return(mockOrm).Times(4) + mockOrm.EXPECT().Query().Return(mockQuery).Times(3) + mockSchema.EXPECT().Orm().Return(mockOrm).Times(3) + mockQuery.EXPECT().Driver().Return("mysql").Once() mockQuery.EXPECT().Raw("SELECT VERSION() AS value;").Return(mockQuery).Once() mockQuery.EXPECT().Raw("SHOW status WHERE variable_name = 'threads_connected';").Return(mockQuery).Once() mockQuery.EXPECT().Scan(&queryResult{}).Return(nil).Twice() @@ -86,9 +85,9 @@ func TestShowCommand(t *testing.T) { mockConfig.EXPECT().GetString("database.connections.test.host").Return("host").Once() mockConfig.EXPECT().GetString("database.connections.test.port").Return("port").Once() mockConfig.EXPECT().GetString("database.connections.test.username").Return("username").Once() - mockQuery.EXPECT().Driver().Return(database.DriverMysql).Twice() - mockOrm.EXPECT().Query().Return(mockQuery).Times(4) - mockSchema.EXPECT().Orm().Return(mockOrm).Times(4) + mockOrm.EXPECT().Query().Return(mockQuery).Times(3) + mockSchema.EXPECT().Orm().Return(mockOrm).Times(3) + mockQuery.EXPECT().Driver().Return("mysql").Once() mockQuery.EXPECT().Raw("SELECT VERSION() AS value;").Return(mockQuery).Once() mockQuery.EXPECT().Raw("SHOW status WHERE variable_name = 'threads_connected';").Return(mockQuery).Once() mockQuery.EXPECT().Scan(&queryResult{}).Return(nil).Twice() @@ -109,9 +108,9 @@ func TestShowCommand(t *testing.T) { mockConfig.EXPECT().GetString("database.connections.test.host").Return("host").Once() mockConfig.EXPECT().GetString("database.connections.test.port").Return("port").Once() mockConfig.EXPECT().GetString("database.connections.test.username").Return("username").Once() - mockQuery.EXPECT().Driver().Return(database.DriverMysql).Twice() - mockOrm.EXPECT().Query().Return(mockQuery).Times(5) - mockSchema.EXPECT().Orm().Return(mockOrm).Times(5) + mockOrm.EXPECT().Query().Return(mockQuery).Times(4) + mockSchema.EXPECT().Orm().Return(mockOrm).Times(4) + mockQuery.EXPECT().Driver().Return("mysql").Once() mockQuery.EXPECT().Raw("SELECT VERSION() AS value;").Return(mockQuery).Once() mockQuery.EXPECT().Raw("SHOW status WHERE variable_name = 'threads_connected';").Return(mockQuery).Once() mockQuery.EXPECT().Scan(&queryResult{}).Run(func(dest interface{}) { diff --git a/database/gorm/event.go b/database/gorm/event.go index 5f893cfec..ce3405367 100644 --- a/database/gorm/event.go +++ b/database/gorm/event.go @@ -92,7 +92,7 @@ func (e *Event) IsDirty(columns ...string) bool { } func (e *Event) Query() orm.Query { - return NewQuery(e.query.ctx, e.query.config, e.query.dbConfig, e.query.instance.Session(&gorm.Session{NewDB: true}), e.query.log, e.query.modelToObserver, nil) + return NewQuery(e.query.ctx, e.query.config, e.query.dbConfig, e.query.instance.Session(&gorm.Session{NewDB: true}), e.query.gormQuery, e.query.log, e.query.modelToObserver, nil) } func (e *Event) SetAttribute(key string, value any) { diff --git a/database/gorm/hints/with_hint.go b/database/gorm/hints/with_hint.go deleted file mode 100644 index f75e34253..000000000 --- a/database/gorm/hints/with_hint.go +++ /dev/null @@ -1,58 +0,0 @@ -package hints - -import ( - "gorm.io/driver/sqlserver" - "gorm.io/gorm" - "gorm.io/gorm/clause" -) - -type WithHint struct { - Type string - Keys []string -} - -func (indexHint WithHint) ModifyStatement(stmt *gorm.Statement) { - dialector := sqlserver.Dialector{} - if stmt.Name() == dialector.Name() { - for _, name := range []string{"FROM"} { - clause := stmt.Clauses[name] - - if clause.AfterExpression == nil { - clause.AfterExpression = indexHint - } else { - clause.AfterExpression = Exprs{clause.AfterExpression, indexHint} - } - - stmt.Clauses[name] = clause - } - } -} - -func (indexHint WithHint) Build(builder clause.Builder) { - if len(indexHint.Keys) > 0 { - _, _ = builder.WriteString(indexHint.Type) - _ = builder.WriteByte('(') - for idx, key := range indexHint.Keys { - if idx > 0 { - _ = builder.WriteByte(',') - } - _, _ = builder.WriteString(key) - } - _ = builder.WriteByte(')') - } -} - -func With(names ...string) WithHint { - return WithHint{Type: "with ", Keys: names} -} - -type Exprs []clause.Expression - -func (exprs Exprs) Build(builder clause.Builder) { - for idx, expr := range exprs { - if idx > 0 { - _ = builder.WriteByte(' ') - } - expr.Build(builder) - } -} diff --git a/database/gorm/query.go b/database/gorm/query.go index a45283200..6e6da7ba5 100644 --- a/database/gorm/query.go +++ b/database/gorm/query.go @@ -16,7 +16,6 @@ import ( "github.com/goravel/framework/contracts/database/driver" contractsorm "github.com/goravel/framework/contracts/database/orm" "github.com/goravel/framework/contracts/log" - "github.com/goravel/framework/database/gorm/hints" "github.com/goravel/framework/errors" "github.com/goravel/framework/support/database" ) @@ -29,6 +28,7 @@ type Query struct { ctx context.Context dbConfig contractsdatabase.Config instance *gormio.DB + gormQuery driver.GormQuery log log.Log modelToObserver []contractsorm.ModelToObserver mutex sync.Mutex @@ -40,6 +40,7 @@ func NewQuery( config config.Config, dbConfig contractsdatabase.Config, db *gormio.DB, + gormQuery driver.GormQuery, log log.Log, modelToObserver []contractsorm.ModelToObserver, conditions *Conditions, @@ -49,6 +50,7 @@ func NewQuery( ctx: ctx, dbConfig: dbConfig, instance: db, + gormQuery: gormQuery, log: log, modelToObserver: modelToObserver, queries: make(map[string]*Query), @@ -72,12 +74,12 @@ func BuildQuery(ctx context.Context, config config.Config, connection string, lo return nil, err } - gorm, err := driver.Gorm() + gorm, gormQuery, err := driver.Gorm() if err != nil { return nil, err } - return NewQuery(ctx, config, driver.Config(), gorm, log, modelToObserver, nil), nil + return NewQuery(ctx, config, driver.Config(), gorm, gormQuery, log, modelToObserver, nil), nil } func (r *Query) Association(association string) contractsorm.Association { @@ -204,8 +206,8 @@ func (r *Query) Distinct(args ...any) contractsorm.Query { return r.setConditions(conditions) } -func (r *Query) Driver() contractsdatabase.Driver { - return contractsdatabase.Driver(r.instance.Dialector.Name()) +func (r *Query) Driver() string { + return r.dbConfig.Driver } func (r *Query) Exec(sql string, values ...any) (*contractsorm.Result, error) { @@ -579,18 +581,7 @@ func (r *Query) Instance() *gormio.DB { } func (r *Query) InRandomOrder() contractsorm.Query { - order := "" - switch r.Driver() { - case contractsdatabase.DriverMysql: - order = "RAND()" - case contractsdatabase.DriverSqlserver: - order = "NEWID()" - case contractsdatabase.DriverPostgres: - order = "RANDOM()" - case contractsdatabase.DriverSqlite: - order = "RANDOM()" - } - return r.Order(order) + return r.Order(r.gormQuery.RandomOrder()) } func (r *Query) InTransaction() bool { @@ -1050,12 +1041,9 @@ func (r *Query) buildLockForUpdate(db *gormio.DB) *gormio.DB { return db } - driver := r.instance.Name() - // TODO To Check if the hardcoded driver names can be optimized - if driver == "mysql" || driver == "postgres" { - return db.Clauses(clause.Locking{Strength: "UPDATE"}) - } else if driver == "sqlserver" { - return db.Clauses(hints.With("rowlock", "updlock", "holdlock")) + lockForUpdate := r.gormQuery.LockForUpdate() + if lockForUpdate != nil { + return db.Clauses(lockForUpdate) } r.conditions.lockForUpdate = false @@ -1155,12 +1143,9 @@ func (r *Query) buildSharedLock(db *gormio.DB) *gormio.DB { return db } - driver := r.instance.Name() - // TODO To Check if the hardcoded driver names can be optimized - if driver == "mysql" || driver == "postgres" { - return db.Clauses(clause.Locking{Strength: "SHARE"}) - } else if driver == "sqlserver" { - return db.Clauses(hints.With("rowlock", "holdlock")) + sharedLock := r.gormQuery.SharedLock() + if sharedLock != nil { + return db.Clauses(sharedLock) } r.conditions.sharedLock = false @@ -1208,7 +1193,7 @@ func (r *Query) buildWith(db *gormio.DB) *gormio.DB { if arg, ok := item.args[0].(func(contractsorm.Query) contractsorm.Query); ok { newArgs := []any{ func(tx *gormio.DB) *gormio.DB { - queryImpl := NewQuery(r.ctx, r.config, r.dbConfig, tx, r.log, r.modelToObserver, nil) + queryImpl := NewQuery(r.ctx, r.config, r.dbConfig, tx, r.gormQuery, r.log, r.modelToObserver, nil) query := arg(queryImpl) queryImpl = query.(*Query) queryImpl = queryImpl.buildConditions() @@ -1361,7 +1346,7 @@ func (r *Query) getObserver(dest any) contractsorm.Observer { } func (r *Query) new(db *gormio.DB) *Query { - return NewQuery(r.ctx, r.config, r.dbConfig, db, r.log, r.modelToObserver, &r.conditions) + return NewQuery(r.ctx, r.config, r.dbConfig, db, r.gormQuery, r.log, r.modelToObserver, &r.conditions) } func (r *Query) omitCreate(value any) error { diff --git a/database/migration/test_utils.go b/database/migration/test_utils.go deleted file mode 100644 index 3a2772420..000000000 --- a/database/migration/test_utils.go +++ /dev/null @@ -1,120 +0,0 @@ -package migration - -import ( - "github.com/goravel/framework/contracts/database" - "github.com/goravel/framework/support/carbon" - "github.com/goravel/framework/support/file" -) - -type Agent struct { - ID uint `gorm:"primaryKey" json:"id"` - Name string - CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"` - UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"` -} - -func CreateTestMigrations(driver database.Driver) { - switch driver { - case database.DriverPostgres: - createPostgresMigrations() - case database.DriverMysql: - createMysqlMigrations() - case database.DriverSqlserver: - createSqlserverMigrations() - case database.DriverSqlite: - createSqliteMigrations() - } -} - -func createMysqlMigrations() { - err := file.Create("database/migrations/20230311160527_create_agents_table.up.sql", - `CREATE TABLE agents ( - id bigint(20) unsigned NOT NULL AUTO_INCREMENT, - name varchar(255) NOT NULL, - created_at datetime(3) NOT NULL, - updated_at datetime(3) NOT NULL, - PRIMARY KEY (id), - KEY idx_agents_created_at (created_at), - KEY idx_agents_updated_at (updated_at) -) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; -INSERT INTO agents (name, created_at, updated_at) VALUES ('goravel', '2023-03-11 16:07:41', '2023-03-11 16:07:45'); -`) - if err != nil { - panic(err) - } - - err = file.Create("database/migrations/20230311160527_create_agents_table.down.sql", - `DROP TABLE agents; -`) - if err != nil { - panic(err) - } -} - -func createPostgresMigrations() { - err := file.Create("database/migrations/20230311160527_create_agents_table.up.sql", - `CREATE TABLE agents ( - id SERIAL PRIMARY KEY NOT NULL, - name varchar(255) NOT NULL, - created_at timestamp NOT NULL, - updated_at timestamp NOT NULL -); -INSERT INTO agents (name, created_at, updated_at) VALUES ('goravel', '2023-03-11 16:07:41', '2023-03-11 16:07:45'); -`) - if err != nil { - panic(err) - } - - err = file.Create("database/migrations/20230311160527_create_agents_table.down.sql", - `DROP TABLE agents; -`) - if err != nil { - panic(err) - } -} - -func createSqlserverMigrations() { - err := file.Create("database/migrations/20230311160527_create_agents_table.up.sql", - `CREATE TABLE agents ( - id bigint NOT NULL IDENTITY(1,1), - name varchar(255) NOT NULL, - created_at datetime NOT NULL, - updated_at datetime NOT NULL, - PRIMARY KEY (id) -); -INSERT INTO agents (name, created_at, updated_at) VALUES ('goravel', '2023-03-11 16:07:41', '2023-03-11 16:07:45'); -`) - if err != nil { - panic(err) - } - - err = file.Create("database/migrations/20230311160527_create_agents_table.down.sql", - `DROP TABLE agents; -`) - - if err != nil { - panic(err) - } -} - -func createSqliteMigrations() { - err := file.Create("database/migrations/20230311160527_create_agents_table.up.sql", - `CREATE TABLE agents ( - id integer PRIMARY KEY AUTOINCREMENT NOT NULL, - name varchar(255) NOT NULL, - created_at datetime NOT NULL, - updated_at datetime NOT NULL -); -INSERT INTO agents (name, created_at, updated_at) VALUES ('goravel', '2023-03-11 16:07:41', '2023-03-11 16:07:45'); -`) - if err != nil { - panic(err) - } - - err = file.Create("database/migrations/20230311160527_create_agents_table.down.sql", - `DROP TABLE agents; -`) - if err != nil { - panic(err) - } -} diff --git a/database/schema/blueprint.go b/database/schema/blueprint.go index 0da1f2c91..5fae56d58 100644 --- a/database/schema/blueprint.go +++ b/database/schema/blueprint.go @@ -4,12 +4,34 @@ import ( "fmt" "strings" - ormcontract "github.com/goravel/framework/contracts/database/orm" + "github.com/goravel/framework/contracts/database/orm" "github.com/goravel/framework/contracts/database/schema" - "github.com/goravel/framework/database/schema/constants" "github.com/goravel/framework/support/convert" ) +const ( + CommandAdd = "add" + CommandComment = "comment" + CommandCreate = "create" + CommandDefault = "default" + CommandDrop = "drop" + CommandDropColumn = "dropColumn" + CommandDropForeign = "dropForeign" + CommandDropFullText = "dropFullText" + CommandDropIfExists = "dropIfExists" + CommandDropIndex = "dropIndex" + CommandDropPrimary = "dropPrimary" + CommandDropUnique = "dropUnique" + CommandForeign = "foreign" + CommandFullText = "fullText" + CommandIndex = "index" + CommandPrimary = "primary" + CommandRename = "rename" + CommandRenameIndex = "renameIndex" + CommandUnique = "unique" + DefaultStringLength = 255 +) + type Blueprint struct { columns []*ColumnDefinition commands []*schema.Command @@ -34,7 +56,7 @@ func (r *Blueprint) BigInteger(column string) schema.ColumnDefinition { return r.createAndAddColumn("bigInteger", column) } -func (r *Blueprint) Build(query ormcontract.Query, grammar schema.Grammar) error { +func (r *Blueprint) Build(query orm.Query, grammar schema.Grammar) error { for _, sql := range r.ToSql(grammar) { if _, err := query.Exec(sql); err != nil { return err @@ -45,7 +67,7 @@ func (r *Blueprint) Build(query ormcontract.Query, grammar schema.Grammar) error } func (r *Blueprint) Char(column string, length ...int) schema.ColumnDefinition { - defaultLength := constants.DefaultStringLength + defaultLength := DefaultStringLength if len(length) > 0 { defaultLength = length[0] } @@ -58,7 +80,7 @@ func (r *Blueprint) Char(column string, length ...int) schema.ColumnDefinition { func (r *Blueprint) Create() { r.addCommand(&schema.Command{ - Name: constants.CommandCreate, + Name: CommandCreate, }) } @@ -94,62 +116,62 @@ func (r *Blueprint) Double(column string) schema.ColumnDefinition { func (r *Blueprint) Drop() { r.addCommand(&schema.Command{ - Name: constants.CommandDrop, + Name: CommandDrop, }) } func (r *Blueprint) DropColumn(column ...string) { r.addCommand(&schema.Command{ - Name: constants.CommandDropColumn, + Name: CommandDropColumn, Columns: column, }) } func (r *Blueprint) DropForeign(column ...string) { - r.indexCommand(constants.CommandDropForeign, column, schema.IndexConfig{ - Name: r.createIndexName(constants.CommandForeign, column), + r.indexCommand(CommandDropForeign, column, schema.IndexConfig{ + Name: r.createIndexName(CommandForeign, column), }) } func (r *Blueprint) DropForeignByName(name string) { - r.indexCommand(constants.CommandDropForeign, nil, schema.IndexConfig{ + r.indexCommand(CommandDropForeign, nil, schema.IndexConfig{ Name: name, }) } func (r *Blueprint) DropFullText(column ...string) { - r.indexCommand(constants.CommandDropFullText, column, schema.IndexConfig{ - Name: r.createIndexName(constants.CommandFullText, column), + r.indexCommand(CommandDropFullText, column, schema.IndexConfig{ + Name: r.createIndexName(CommandFullText, column), }) } func (r *Blueprint) DropFullTextByName(name string) { - r.indexCommand(constants.CommandDropFullText, nil, schema.IndexConfig{ + r.indexCommand(CommandDropFullText, nil, schema.IndexConfig{ Name: name, }) } func (r *Blueprint) DropIfExists() { r.addCommand(&schema.Command{ - Name: constants.CommandDropIfExists, + Name: CommandDropIfExists, }) } func (r *Blueprint) DropIndex(column ...string) { - r.indexCommand(constants.CommandDropIndex, column, schema.IndexConfig{ - Name: r.createIndexName(constants.CommandIndex, column), + r.indexCommand(CommandDropIndex, column, schema.IndexConfig{ + Name: r.createIndexName(CommandIndex, column), }) } func (r *Blueprint) DropIndexByName(name string) { - r.indexCommand(constants.CommandDropIndex, nil, schema.IndexConfig{ + r.indexCommand(CommandDropIndex, nil, schema.IndexConfig{ Name: name, }) } func (r *Blueprint) DropPrimary(column ...string) { - r.indexCommand(constants.CommandDropPrimary, column, schema.IndexConfig{ - Name: r.createIndexName(constants.CommandPrimary, column), + r.indexCommand(CommandDropPrimary, column, schema.IndexConfig{ + Name: r.createIndexName(CommandPrimary, column), }) } @@ -174,13 +196,13 @@ func (r *Blueprint) DropTimestampsTz() { } func (r *Blueprint) DropUnique(column ...string) { - r.indexCommand(constants.CommandDropUnique, column, schema.IndexConfig{ - Name: r.createIndexName(constants.CommandUnique, column), + r.indexCommand(CommandDropUnique, column, schema.IndexConfig{ + Name: r.createIndexName(CommandUnique, column), }) } func (r *Blueprint) DropUniqueByName(name string) { - r.indexCommand(constants.CommandDropUnique, nil, schema.IndexConfig{ + r.indexCommand(CommandDropUnique, nil, schema.IndexConfig{ Name: name, }) } @@ -204,13 +226,13 @@ func (r *Blueprint) Float(column string, precision ...int) schema.ColumnDefiniti } func (r *Blueprint) Foreign(column ...string) schema.ForeignKeyDefinition { - command := r.indexCommand(constants.CommandForeign, column) + command := r.indexCommand(CommandForeign, column) return NewForeignKeyDefinition(command) } func (r *Blueprint) FullText(column ...string) schema.IndexDefinition { - command := r.indexCommand(constants.CommandFullText, column) + command := r.indexCommand(CommandFullText, column) return NewIndexDefinition(command) } @@ -255,7 +277,7 @@ func (r *Blueprint) Increments(column string) schema.ColumnDefinition { } func (r *Blueprint) Index(column ...string) schema.IndexDefinition { - command := r.indexCommand(constants.CommandIndex, column) + command := r.indexCommand(CommandIndex, column) return NewIndexDefinition(command) } @@ -293,12 +315,12 @@ func (r *Blueprint) MediumText(column string) schema.ColumnDefinition { } func (r *Blueprint) Primary(column ...string) { - r.indexCommand(constants.CommandPrimary, column) + r.indexCommand(CommandPrimary, column) } func (r *Blueprint) Rename(to string) { command := &schema.Command{ - Name: constants.CommandRename, + Name: CommandRename, To: to, } @@ -307,7 +329,7 @@ func (r *Blueprint) Rename(to string) { func (r *Blueprint) RenameIndex(from, to string) { command := &schema.Command{ - Name: constants.CommandRenameIndex, + Name: CommandRenameIndex, From: from, To: to, } @@ -346,7 +368,7 @@ func (r *Blueprint) SoftDeletesTz(column ...string) schema.ColumnDefinition { } func (r *Blueprint) String(column string, length ...int) schema.ColumnDefinition { - defaultLength := constants.DefaultStringLength + defaultLength := DefaultStringLength if len(length) > 0 { defaultLength = length[0] } @@ -429,7 +451,7 @@ func (r *Blueprint) ToSql(grammar schema.Grammar) []string { } switch command.Name { - case constants.CommandAdd: + case CommandAdd: if command.Column.IsChange() { if statement := grammar.CompileChange(r, command); len(statement) > 0 { statements = append(statements, statement...) @@ -437,45 +459,45 @@ func (r *Blueprint) ToSql(grammar schema.Grammar) []string { continue } statements = append(statements, grammar.CompileAdd(r, command)) - case constants.CommandComment: + case CommandComment: if statement := grammar.CompileComment(r, command); statement != "" { statements = append(statements, statement) } - case constants.CommandCreate: + case CommandCreate: statements = append(statements, grammar.CompileCreate(r)) - case constants.CommandDefault: + case CommandDefault: if statement := grammar.CompileDefault(r, command); statement != "" { statements = append(statements, statement) } - case constants.CommandDrop: + case CommandDrop: statements = append(statements, grammar.CompileDrop(r)) - case constants.CommandDropColumn: + case CommandDropColumn: statements = append(statements, grammar.CompileDropColumn(r, command)...) - case constants.CommandDropForeign: + case CommandDropForeign: statements = append(statements, grammar.CompileDropForeign(r, command)) - case constants.CommandDropFullText: + case CommandDropFullText: statements = append(statements, grammar.CompileDropFullText(r, command)) - case constants.CommandDropIfExists: + case CommandDropIfExists: statements = append(statements, grammar.CompileDropIfExists(r)) - case constants.CommandDropIndex: + case CommandDropIndex: statements = append(statements, grammar.CompileDropIndex(r, command)) - case constants.CommandDropPrimary: + case CommandDropPrimary: statements = append(statements, grammar.CompileDropPrimary(r, command)) - case constants.CommandDropUnique: + case CommandDropUnique: statements = append(statements, grammar.CompileDropUnique(r, command)) - case constants.CommandForeign: + case CommandForeign: statements = append(statements, grammar.CompileForeign(r, command)) - case constants.CommandFullText: + case CommandFullText: statements = append(statements, grammar.CompileFullText(r, command)) - case constants.CommandIndex: + case CommandIndex: statements = append(statements, grammar.CompileIndex(r, command)) - case constants.CommandPrimary: + case CommandPrimary: statements = append(statements, grammar.CompilePrimary(r, command)) - case constants.CommandRename: + case CommandRename: statements = append(statements, grammar.CompileRename(r, command)) - case constants.CommandRenameIndex: + case CommandRenameIndex: statements = append(statements, grammar.CompileRenameIndex(r.schema, r, command)...) - case constants.CommandUnique: + case CommandUnique: statements = append(statements, grammar.CompileUnique(r, command)) } } @@ -484,7 +506,7 @@ func (r *Blueprint) ToSql(grammar schema.Grammar) []string { } func (r *Blueprint) Unique(column ...string) schema.IndexDefinition { - command := r.indexCommand(constants.CommandUnique, column) + command := r.indexCommand(CommandUnique, column) return NewIndexDefinition(command) } @@ -513,16 +535,16 @@ func (r *Blueprint) addAttributeCommands(grammar schema.Grammar) { attributeCommands := grammar.GetAttributeCommands() for _, column := range r.columns { for _, command := range attributeCommands { - if command == constants.CommandComment && (column.comment != nil || column.change) { + if command == CommandComment && (column.comment != nil || column.change) { r.addCommand(&schema.Command{ Column: column, - Name: constants.CommandComment, + Name: CommandComment, }) } - if command == constants.CommandDefault && column.def != nil { + if command == CommandDefault && column.def != nil { r.addCommand(&schema.Command{ Column: column, - Name: constants.CommandDefault, + Name: CommandDefault, }) } } @@ -547,7 +569,7 @@ func (r *Blueprint) createAndAddColumn(ttype, name string) *ColumnDefinition { if !r.isCreate() { r.addCommand(&schema.Command{ - Name: constants.CommandAdd, + Name: CommandAdd, Column: columnImpl, }) } @@ -593,7 +615,7 @@ func (r *Blueprint) indexCommand(name string, columns []string, config ...schema func (r *Blueprint) isCreate() bool { for _, command := range r.commands { - if command.Name == constants.CommandCreate { + if command.Name == CommandCreate { return true } } diff --git a/database/schema/blueprint_test.go b/database/schema/blueprint_test.go index 79f6ae1c9..f3dcc4226 100644 --- a/database/schema/blueprint_test.go +++ b/database/schema/blueprint_test.go @@ -7,7 +7,6 @@ import ( "github.com/stretchr/testify/suite" "github.com/goravel/framework/contracts/database/schema" - "github.com/goravel/framework/database/schema/constants" mocksorm "github.com/goravel/framework/mocks/database/orm" mocksschema "github.com/goravel/framework/mocks/database/schema" "github.com/goravel/framework/support/convert" @@ -195,7 +194,7 @@ func (s *BlueprintTestSuite) TestBuild() { func (s *BlueprintTestSuite) TestChar() { column := "name" customLength := 100 - length := constants.DefaultStringLength + length := DefaultStringLength ttype := "char" s.blueprint.Char(column) s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{ @@ -269,9 +268,9 @@ func (s *BlueprintTestSuite) TestGetAddedColumns() { } func (s *BlueprintTestSuite) TestHasCommand() { - s.False(s.blueprint.HasCommand(constants.CommandCreate)) + s.False(s.blueprint.HasCommand(CommandCreate)) s.blueprint.Create() - s.True(s.blueprint.HasCommand(constants.CommandCreate)) + s.True(s.blueprint.HasCommand(CommandCreate)) } func (s *BlueprintTestSuite) TestIntegerIncrements() { @@ -309,7 +308,7 @@ func (s *BlueprintTestSuite) TestIsCreate() { s.False(s.blueprint.isCreate()) s.blueprint.commands = []*schema.Command{ { - Name: constants.CommandCreate, + Name: CommandCreate, }, } s.True(s.blueprint.isCreate()) @@ -385,7 +384,7 @@ func (s *BlueprintTestSuite) TestSmallInteger() { func (s *BlueprintTestSuite) TestString() { column := "name" customLength := 100 - length := constants.DefaultStringLength + length := DefaultStringLength ttype := "string" s.blueprint.String(column) s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{ @@ -459,7 +458,7 @@ func (s *BlueprintTestSuite) TestToSql() { Return("sql1").Once() mockGrammar.EXPECT().CompileComment(s.blueprint, &schema.Command{ Column: s.blueprint.columns[0], - Name: constants.CommandComment, + Name: CommandComment, }).Return("sql2").Once() }, expectedSQL: []string{"sql1", "sql2"}, @@ -473,7 +472,7 @@ func (s *BlueprintTestSuite) TestToSql() { Return("sql1").Once() mockGrammar.EXPECT().CompileDefault(s.blueprint, &schema.Command{ Column: s.blueprint.columns[0], - Name: constants.CommandDefault, + Name: CommandDefault, }).Return("sql2").Once() }, expectedSQL: []string{"sql1", "sql2"}, diff --git a/database/schema/common_schema.go b/database/schema/common_schema.go deleted file mode 100644 index c0b2b8fb1..000000000 --- a/database/schema/common_schema.go +++ /dev/null @@ -1,36 +0,0 @@ -package schema - -import ( - "github.com/goravel/framework/contracts/database/orm" - "github.com/goravel/framework/contracts/database/schema" -) - -type CommonSchema struct { - grammar schema.Grammar - orm orm.Orm -} - -func NewCommonSchema(grammar schema.Grammar, orm orm.Orm) *CommonSchema { - return &CommonSchema{ - grammar: grammar, - orm: orm, - } -} - -func (r *CommonSchema) GetTables() ([]schema.Table, error) { - var tables []schema.Table - if err := r.orm.Query().Raw(r.grammar.CompileTables(r.orm.DatabaseName())).Scan(&tables); err != nil { - return nil, err - } - - return tables, nil -} - -func (r *CommonSchema) GetViews() ([]schema.View, error) { - var views []schema.View - if err := r.orm.Query().Raw(r.grammar.CompileViews(r.orm.DatabaseName())).Scan(&views); err != nil { - return nil, err - } - - return views, nil -} diff --git a/database/schema/constants/constants.go b/database/schema/constants/constants.go deleted file mode 100644 index b8d4a906b..000000000 --- a/database/schema/constants/constants.go +++ /dev/null @@ -1,24 +0,0 @@ -package constants - -const ( - CommandAdd = "add" - CommandComment = "comment" - CommandCreate = "create" - CommandDefault = "default" - CommandDrop = "drop" - CommandDropColumn = "dropColumn" - CommandDropForeign = "dropForeign" - CommandDropFullText = "dropFullText" - CommandDropIfExists = "dropIfExists" - CommandDropIndex = "dropIndex" - CommandDropPrimary = "dropPrimary" - CommandDropUnique = "dropUnique" - CommandForeign = "foreign" - CommandFullText = "fullText" - CommandIndex = "index" - CommandPrimary = "primary" - CommandRename = "rename" - CommandRenameIndex = "renameIndex" - CommandUnique = "unique" - DefaultStringLength = 255 -) diff --git a/database/schema/grammars/mysql.go b/database/schema/grammars/mysql.go deleted file mode 100644 index fdb99eab1..000000000 --- a/database/schema/grammars/mysql.go +++ /dev/null @@ -1,499 +0,0 @@ -package grammars - -import ( - "fmt" - "slices" - "strings" - - "github.com/spf13/cast" - - contractsdatabase "github.com/goravel/framework/contracts/database" - "github.com/goravel/framework/contracts/database/schema" -) - -type Mysql struct { - attributeCommands []string - modifiers []func(schema.Blueprint, schema.ColumnDefinition) string - serials []string - wrap *Wrap -} - -func NewMysql(tablePrefix string) *Mysql { - mysql := &Mysql{ - attributeCommands: []string{}, - serials: []string{"bigInteger", "integer", "mediumInteger", "smallInteger", "tinyInteger"}, - wrap: NewWrap(contractsdatabase.DriverMysql, tablePrefix), - } - mysql.modifiers = []func(schema.Blueprint, schema.ColumnDefinition) string{ - // The sort should not be changed, it effects the SQL output - mysql.ModifyUnsigned, - mysql.ModifyNullable, - mysql.ModifyDefault, - mysql.ModifyOnUpdate, - mysql.ModifyIncrement, - mysql.ModifyComment, - } - - return mysql -} - -func (r *Mysql) CompileAdd(blueprint schema.Blueprint, command *schema.Command) string { - return fmt.Sprintf("alter table %s add %s", r.wrap.Table(blueprint.GetTableName()), r.getColumn(blueprint, command.Column)) -} - -func (r *Mysql) CompileChange(blueprint schema.Blueprint, command *schema.Command) []string { - return []string{ - fmt.Sprintf("alter table %s modify %s", r.wrap.Table(blueprint.GetTableName()), r.getColumn(blueprint, command.Column)), - } -} - -func (r *Mysql) CompileColumns(schema, table string) string { - return fmt.Sprintf( - "select column_name as `name`, data_type as `type_name`, column_type as `type`, "+ - "collation_name as `collation`, is_nullable as `nullable`, "+ - "column_default as `default`, column_comment as `comment`, "+ - "generation_expression as `expression`, extra as `extra` "+ - "from information_schema.columns where table_schema = %s and table_name = %s "+ - "order by ordinal_position asc", r.wrap.Quote(schema), r.wrap.Quote(table)) -} - -func (r *Mysql) CompileComment(_ schema.Blueprint, _ *schema.Command) string { - return "" -} - -func (r *Mysql) CompileCreate(blueprint schema.Blueprint) string { - columns := r.getColumns(blueprint) - primaryCommand := getCommandByName(blueprint.GetCommands(), "primary") - if primaryCommand != nil { - var algorithm string - if primaryCommand.Algorithm != "" { - algorithm = "using " + primaryCommand.Algorithm - } - columns = append(columns, fmt.Sprintf("primary key %s(%s)", algorithm, r.wrap.Columnize(primaryCommand.Columns))) - - primaryCommand.ShouldBeSkipped = true - } - - return fmt.Sprintf("create table %s (%s)", r.wrap.Table(blueprint.GetTableName()), strings.Join(columns, ", ")) -} - -func (r *Mysql) CompileDefault(_ schema.Blueprint, _ *schema.Command) string { - return "" -} - -func (r *Mysql) CompileDisableForeignKeyConstraints() string { - return "SET FOREIGN_KEY_CHECKS=0;" -} - -func (r *Mysql) CompileDrop(blueprint schema.Blueprint) string { - return fmt.Sprintf("drop table %s", r.wrap.Table(blueprint.GetTableName())) -} - -func (r *Mysql) CompileDropAllDomains(_ []string) string { - return "" -} - -func (r *Mysql) CompileDropAllTables(tables []string) string { - return fmt.Sprintf("drop table %s", r.wrap.Columnize(tables)) -} - -func (r *Mysql) CompileDropAllTypes(_ []string) string { - return "" -} - -func (r *Mysql) CompileDropAllViews(views []string) string { - return fmt.Sprintf("drop view %s", r.wrap.Columnize(views)) -} - -func (r *Mysql) CompileDropColumn(blueprint schema.Blueprint, command *schema.Command) []string { - columns := r.wrap.PrefixArray("drop", r.wrap.Columns(command.Columns)) - - return []string{ - fmt.Sprintf("alter table %s %s", r.wrap.Table(blueprint.GetTableName()), strings.Join(columns, ", ")), - } -} - -func (r *Mysql) CompileDropForeign(blueprint schema.Blueprint, command *schema.Command) string { - return fmt.Sprintf("alter table %s drop foreign key %s", r.wrap.Table(blueprint.GetTableName()), r.wrap.Column(command.Index)) -} - -func (r *Mysql) CompileDropFullText(blueprint schema.Blueprint, command *schema.Command) string { - return r.CompileDropIndex(blueprint, command) -} - -func (r *Mysql) CompileDropIfExists(blueprint schema.Blueprint) string { - return fmt.Sprintf("drop table if exists %s", r.wrap.Table(blueprint.GetTableName())) -} - -func (r *Mysql) CompileDropIndex(blueprint schema.Blueprint, command *schema.Command) string { - return fmt.Sprintf("alter table %s drop index %s", r.wrap.Table(blueprint.GetTableName()), r.wrap.Column(command.Index)) -} - -func (r *Mysql) CompileDropPrimary(blueprint schema.Blueprint, _ *schema.Command) string { - return fmt.Sprintf("alter table %s drop primary key", r.wrap.Table(blueprint.GetTableName())) -} - -func (r *Mysql) CompileDropUnique(blueprint schema.Blueprint, command *schema.Command) string { - return r.CompileDropIndex(blueprint, command) -} - -func (r *Mysql) CompileEnableForeignKeyConstraints() string { - return "SET FOREIGN_KEY_CHECKS=1;" -} - -func (r *Mysql) CompileForeign(blueprint schema.Blueprint, command *schema.Command) string { - sql := fmt.Sprintf("alter table %s add constraint %s foreign key (%s) references %s (%s)", - r.wrap.Table(blueprint.GetTableName()), - r.wrap.Column(command.Index), - r.wrap.Columnize(command.Columns), - r.wrap.Table(command.On), - r.wrap.Columnize(command.References)) - if command.OnDelete != "" { - sql += " on delete " + command.OnDelete - } - if command.OnUpdate != "" { - sql += " on update " + command.OnUpdate - } - - return sql -} - -func (r *Mysql) CompileForeignKeys(schema, table string) string { - return fmt.Sprintf( - `SELECT - kc.constraint_name AS name, - GROUP_CONCAT(kc.column_name ORDER BY kc.ordinal_position) AS columns, - kc.referenced_table_schema AS foreign_schema, - kc.referenced_table_name AS foreign_table, - GROUP_CONCAT(kc.referenced_column_name ORDER BY kc.ordinal_position) AS foreign_columns, - rc.update_rule AS on_update, - rc.delete_rule AS on_delete - FROM information_schema.key_column_usage kc - JOIN information_schema.referential_constraints rc - ON kc.constraint_schema = rc.constraint_schema - AND kc.constraint_name = rc.constraint_name - WHERE kc.table_schema = %s - AND kc.table_name = %s - AND kc.referenced_table_name IS NOT NULL - GROUP BY - kc.constraint_name, - kc.referenced_table_schema, - kc.referenced_table_name, - rc.update_rule, - rc.delete_rule`, - r.wrap.Quote(schema), - r.wrap.Quote(table), - ) -} - -func (r *Mysql) CompileFullText(blueprint schema.Blueprint, command *schema.Command) string { - return r.compileKey(blueprint, command, "fulltext") -} - -func (r *Mysql) CompileIndex(blueprint schema.Blueprint, command *schema.Command) string { - var algorithm string - if command.Algorithm != "" { - algorithm = " using " + command.Algorithm - } - - return fmt.Sprintf("alter table %s add %s %s%s(%s)", - r.wrap.Table(blueprint.GetTableName()), - "index", - r.wrap.Column(command.Index), - algorithm, - r.wrap.Columnize(command.Columns), - ) -} - -func (r *Mysql) CompileIndexes(schema, table string) string { - return fmt.Sprintf( - "select index_name as `name`, group_concat(column_name order by seq_in_index) as `columns`, "+ - "index_type as `type`, not non_unique as `unique` "+ - "from information_schema.statistics where table_schema = %s and table_name = %s "+ - "group by index_name, index_type, non_unique", - r.wrap.Quote(schema), - r.wrap.Quote(table), - ) -} - -func (r *Mysql) CompilePrimary(blueprint schema.Blueprint, command *schema.Command) string { - var algorithm string - if command.Algorithm != "" { - algorithm = "using " + command.Algorithm - } - - return fmt.Sprintf("alter table %s add primary key %s(%s)", r.wrap.Table(blueprint.GetTableName()), algorithm, r.wrap.Columnize(command.Columns)) -} - -func (r *Mysql) CompileRename(blueprint schema.Blueprint, command *schema.Command) string { - return fmt.Sprintf("rename table %s to %s", r.wrap.Table(blueprint.GetTableName()), r.wrap.Table(command.To)) -} - -func (r *Mysql) CompileRenameIndex(_ schema.Schema, blueprint schema.Blueprint, command *schema.Command) []string { - return []string{ - fmt.Sprintf("alter table %s rename index %s to %s", r.wrap.Table(blueprint.GetTableName()), r.wrap.Column(command.From), r.wrap.Column(command.To)), - } -} - -func (r *Mysql) CompileTables(database string) string { - return fmt.Sprintf("select table_name as `name`, (data_length + index_length) as `size`, "+ - "table_comment as `comment`, engine as `engine`, table_collation as `collation` "+ - "from information_schema.tables where table_schema = %s and table_type in ('BASE TABLE', 'SYSTEM VERSIONED') "+ - "order by table_name", r.wrap.Quote(database)) -} - -func (r *Mysql) CompileTypes() string { - return "" -} - -func (r *Mysql) CompileUnique(blueprint schema.Blueprint, command *schema.Command) string { - return r.compileKey(blueprint, command, "unique") -} - -func (r *Mysql) CompileViews(database string) string { - return fmt.Sprintf("select table_name as `name`, view_definition as `definition` "+ - "from information_schema.views where table_schema = %s "+ - "order by table_name", r.wrap.Quote(database)) -} - -func (r *Mysql) GetAttributeCommands() []string { - return r.attributeCommands -} - -func (r *Mysql) ModifyComment(_ schema.Blueprint, column schema.ColumnDefinition) string { - if comment := column.GetComment(); comment != "" { - // Escape special characters to prevent SQL injection - comment = strings.ReplaceAll(comment, "'", "''") - comment = strings.ReplaceAll(comment, "\\", "\\\\") - - return fmt.Sprintf(" comment '%s'", comment) - } - - return "" -} - -func (r *Mysql) ModifyDefault(_ schema.Blueprint, column schema.ColumnDefinition) string { - if column.GetDefault() != nil { - return fmt.Sprintf(" default %s", getDefaultValue(column.GetDefault())) - } - - return "" -} - -func (r *Mysql) ModifyNullable(_ schema.Blueprint, column schema.ColumnDefinition) string { - if column.GetNullable() { - return " null" - } else { - return " not null" - } -} - -func (r *Mysql) ModifyIncrement(blueprint schema.Blueprint, column schema.ColumnDefinition) string { - if slices.Contains(r.serials, column.GetType()) && column.GetAutoIncrement() { - if blueprint.HasCommand("primary") { - return "auto_increment" - } - return " auto_increment primary key" - } - - return "" -} - -func (r *Mysql) ModifyOnUpdate(_ schema.Blueprint, column schema.ColumnDefinition) string { - onUpdate := column.GetOnUpdate() - if onUpdate != nil { - switch value := onUpdate.(type) { - case Expression: - return " on update " + string(value) - case string: - if onUpdate.(string) != "" { - return " on update " + value - } - } - } - - return "" -} - -func (r *Mysql) ModifyUnsigned(_ schema.Blueprint, column schema.ColumnDefinition) string { - if column.GetUnsigned() { - return " unsigned" - } - - return "" -} - -func (r *Mysql) TypeBigInteger(_ schema.ColumnDefinition) string { - return "bigint" -} - -func (r *Mysql) TypeChar(column schema.ColumnDefinition) string { - return fmt.Sprintf("char(%d)", column.GetLength()) -} - -func (r *Mysql) TypeDate(_ schema.ColumnDefinition) string { - return "date" -} - -func (r *Mysql) TypeDateTime(column schema.ColumnDefinition) string { - current := "CURRENT_TIMESTAMP" - precision := column.GetPrecision() - if precision > 0 { - current = fmt.Sprintf("CURRENT_TIMESTAMP(%d)", precision) - } - if column.GetUseCurrent() { - column.Default(Expression(current)) - } - if column.GetUseCurrentOnUpdate() { - column.OnUpdate(Expression(current)) - } - - if precision > 0 { - return fmt.Sprintf("datetime(%d)", precision) - } else { - return "datetime" - } -} - -func (r *Mysql) TypeDateTimeTz(column schema.ColumnDefinition) string { - return r.TypeDateTime(column) -} - -func (r *Mysql) TypeDecimal(column schema.ColumnDefinition) string { - return fmt.Sprintf("decimal(%d, %d)", column.GetTotal(), column.GetPlaces()) -} - -func (r *Mysql) TypeDouble(_ schema.ColumnDefinition) string { - return "double" -} - -func (r *Mysql) TypeEnum(column schema.ColumnDefinition) string { - return fmt.Sprintf(`enum(%s)`, strings.Join(r.wrap.Quotes(cast.ToStringSlice(column.GetAllowed())), ", ")) -} - -func (r *Mysql) TypeFloat(column schema.ColumnDefinition) string { - precision := column.GetPrecision() - if precision > 0 { - return fmt.Sprintf("float(%d)", precision) - } - - return "float" -} - -func (r *Mysql) TypeInteger(_ schema.ColumnDefinition) string { - return "int" -} - -func (r *Mysql) TypeJson(_ schema.ColumnDefinition) string { - return "json" -} - -func (r *Mysql) TypeJsonb(_ schema.ColumnDefinition) string { - return "json" -} - -func (r *Mysql) TypeLongText(_ schema.ColumnDefinition) string { - return "longtext" -} - -func (r *Mysql) TypeMediumInteger(_ schema.ColumnDefinition) string { - return "mediumint" -} - -func (r *Mysql) TypeMediumText(_ schema.ColumnDefinition) string { - return "mediumtext" -} - -func (r *Mysql) TypeSmallInteger(_ schema.ColumnDefinition) string { - return "smallint" -} - -func (r *Mysql) TypeString(column schema.ColumnDefinition) string { - length := column.GetLength() - if length > 0 { - return fmt.Sprintf("varchar(%d)", length) - } - - return "varchar(255)" -} - -func (r *Mysql) TypeText(_ schema.ColumnDefinition) string { - return "text" -} - -func (r *Mysql) TypeTime(column schema.ColumnDefinition) string { - if column.GetPrecision() > 0 { - return fmt.Sprintf("time(%d)", column.GetPrecision()) - } else { - return "time" - } -} - -func (r *Mysql) TypeTimeTz(column schema.ColumnDefinition) string { - return r.TypeTime(column) -} - -func (r *Mysql) TypeTimestamp(column schema.ColumnDefinition) string { - current := "CURRENT_TIMESTAMP" - precision := column.GetPrecision() - if precision > 0 { - current = fmt.Sprintf("CURRENT_TIMESTAMP(%d)", precision) - } - if column.GetUseCurrent() { - column.Default(Expression(current)) - } - if column.GetUseCurrentOnUpdate() { - column.OnUpdate(Expression(current)) - } - - if precision > 0 { - return fmt.Sprintf("timestamp(%d)", precision) - } else { - return "timestamp" - } -} - -func (r *Mysql) TypeTimestampTz(column schema.ColumnDefinition) string { - return r.TypeTimestamp(column) -} - -func (r *Mysql) TypeTinyInteger(_ schema.ColumnDefinition) string { - return "tinyint" -} - -func (r *Mysql) TypeTinyText(_ schema.ColumnDefinition) string { - return "tinytext" -} - -func (r *Mysql) compileKey(blueprint schema.Blueprint, command *schema.Command, ttype string) string { - var algorithm string - if command.Algorithm != "" { - algorithm = " using " + command.Algorithm - } - - return fmt.Sprintf("alter table %s add %s %s%s(%s)", - r.wrap.Table(blueprint.GetTableName()), - ttype, - r.wrap.Column(command.Index), - algorithm, - r.wrap.Columnize(command.Columns)) -} - -func (r *Mysql) getColumns(blueprint schema.Blueprint) []string { - var columns []string - for _, column := range blueprint.GetAddedColumns() { - columns = append(columns, r.getColumn(blueprint, column)) - } - - return columns -} - -func (r *Mysql) getColumn(blueprint schema.Blueprint, column schema.ColumnDefinition) string { - sql := fmt.Sprintf("%s %s", r.wrap.Column(column.GetName()), getType(r, column)) - - for _, modifier := range r.modifiers { - sql += modifier(blueprint, column) - } - - return sql -} diff --git a/database/schema/grammars/mysql_test.go b/database/schema/grammars/mysql_test.go deleted file mode 100644 index 327a7f2d7..000000000 --- a/database/schema/grammars/mysql_test.go +++ /dev/null @@ -1,444 +0,0 @@ -package grammars - -import ( - "testing" - - "github.com/stretchr/testify/suite" - - contractsschema "github.com/goravel/framework/contracts/database/schema" - mocksschema "github.com/goravel/framework/mocks/database/schema" -) - -type MysqlSuite struct { - suite.Suite - grammar *Mysql -} - -func TestMysqlSuite(t *testing.T) { - suite.Run(t, &MysqlSuite{}) -} - -func (s *MysqlSuite) SetupTest() { - s.grammar = NewMysql("goravel_") -} - -func (s *MysqlSuite) TestCompileAdd() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockColumn := mocksschema.NewColumnDefinition(s.T()) - - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - mockColumn.EXPECT().GetName().Return("name").Once() - mockColumn.EXPECT().GetType().Return("string").Twice() - mockColumn.EXPECT().GetDefault().Return("goravel").Twice() - mockColumn.EXPECT().GetNullable().Return(false).Once() - mockColumn.EXPECT().GetLength().Return(1).Once() - mockColumn.EXPECT().GetOnUpdate().Return(nil).Once() - mockColumn.EXPECT().GetComment().Return("comment").Once() - mockColumn.EXPECT().GetUnsigned().Return(false).Once() - - sql := s.grammar.CompileAdd(mockBlueprint, &contractsschema.Command{ - Column: mockColumn, - }) - - s.Equal("alter table `goravel_users` add `name` varchar(1) not null default 'goravel' comment 'comment'", sql) -} - -func (s *MysqlSuite) TestCompileChange() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockColumn := mocksschema.NewColumnDefinition(s.T()) - - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - mockColumn.EXPECT().GetName().Return("name").Once() - mockColumn.EXPECT().GetType().Return("string").Twice() - mockColumn.EXPECT().GetDefault().Return("goravel").Twice() - mockColumn.EXPECT().GetNullable().Return(false).Once() - mockColumn.EXPECT().GetLength().Return(1).Once() - mockColumn.EXPECT().GetOnUpdate().Return(nil).Once() - mockColumn.EXPECT().GetComment().Return("comment").Once() - mockColumn.EXPECT().GetUnsigned().Return(false).Once() - - sql := s.grammar.CompileChange(mockBlueprint, &contractsschema.Command{ - Column: mockColumn, - }) - - s.Equal([]string{"alter table `goravel_users` modify `name` varchar(1) not null default 'goravel' comment 'comment'"}, sql) -} - -func (s *MysqlSuite) TestCompileCreate() { - mockColumn1 := mocksschema.NewColumnDefinition(s.T()) - mockColumn2 := mocksschema.NewColumnDefinition(s.T()) - mockBlueprint := mocksschema.NewBlueprint(s.T()) - - // postgres.go::CompileCreate - primaryCommand := &contractsschema.Command{ - Name: "primary", - Columns: []string{"role_id", "user_id"}, - Algorithm: "btree", - } - mockBlueprint.EXPECT().GetCommands().Return([]*contractsschema.Command{ - primaryCommand, - }).Once() - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - // utils.go::getColumns - mockBlueprint.EXPECT().GetAddedColumns().Return([]contractsschema.ColumnDefinition{ - mockColumn1, mockColumn2, - }).Once() - // utils.go::getColumns - mockColumn1.EXPECT().GetName().Return("id").Once() - // utils.go::getType - mockColumn1.EXPECT().GetType().Return("integer").Once() - // postgres.go::TypeInteger - mockColumn1.EXPECT().GetAutoIncrement().Return(true).Once() - // postgres.go::ModifyDefault - mockColumn1.EXPECT().GetDefault().Return(nil).Once() - // postgres.go::ModifyIncrement - mockBlueprint.EXPECT().HasCommand("primary").Return(false).Once() - mockColumn1.EXPECT().GetType().Return("integer").Once() - // postgres.go::ModifyNullable - mockColumn1.EXPECT().GetNullable().Return(false).Once() - mockColumn1.EXPECT().GetOnUpdate().Return(nil).Once() - mockColumn1.EXPECT().GetComment().Return("id").Once() - mockColumn1.EXPECT().GetUnsigned().Return(true).Once() - - // utils.go::getColumns - mockColumn2.EXPECT().GetName().Return("name").Once() - // utils.go::getType - mockColumn2.EXPECT().GetType().Return("string").Once() - // postgres.go::TypeString - mockColumn2.EXPECT().GetLength().Return(100).Once() - // postgres.go::ModifyDefault - mockColumn2.EXPECT().GetDefault().Return(nil).Once() - // postgres.go::ModifyIncrement - mockColumn2.EXPECT().GetType().Return("string").Once() - // postgres.go::ModifyNullable - mockColumn2.EXPECT().GetNullable().Return(true).Once() - mockColumn2.EXPECT().GetOnUpdate().Return(nil).Once() - mockColumn2.EXPECT().GetComment().Return("name").Once() - mockColumn2.EXPECT().GetUnsigned().Return(false).Once() - - s.Equal("create table `goravel_users` (`id` int unsigned not null auto_increment primary key comment 'id', `name` varchar(100) null comment 'name', primary key using btree(`role_id`, `user_id`))", - s.grammar.CompileCreate(mockBlueprint)) - s.True(primaryCommand.ShouldBeSkipped) -} - -func (s *MysqlSuite) TestCompileDropAllTables() { - s.Equal("drop table `domain`, `email`", s.grammar.CompileDropAllTables([]string{"domain", "email"})) -} - -func (s *MysqlSuite) TestCompileDropAllViews() { - s.Equal("drop view `domain`, `email`", s.grammar.CompileDropAllViews([]string{"domain", "email"})) -} - -func (s *MysqlSuite) TestCompileDropColumn() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - - s.Equal([]string{ - "alter table `goravel_users` drop `id`, drop `name`", - }, s.grammar.CompileDropColumn(mockBlueprint, &contractsschema.Command{ - Columns: []string{"id", "name"}, - })) -} - -func (s *MysqlSuite) TestCompileDropIfExists() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - - s.Equal("drop table if exists `goravel_users`", s.grammar.CompileDropIfExists(mockBlueprint)) -} - -func (s *MysqlSuite) TestCompileForeign() { - var mockBlueprint *mocksschema.Blueprint - - beforeEach := func() { - mockBlueprint = mocksschema.NewBlueprint(s.T()) - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - } - - tests := []struct { - name string - command *contractsschema.Command - expectSql string - }{ - { - name: "with on delete and on update", - command: &contractsschema.Command{ - Index: "fk_users_role_id", - Columns: []string{"role_id", "user_id"}, - On: "roles", - References: []string{"id", "user_id"}, - OnDelete: "cascade", - OnUpdate: "restrict", - }, - expectSql: "alter table `goravel_users` add constraint `fk_users_role_id` foreign key (`role_id`, `user_id`) references `goravel_roles` (`id`, `user_id`) on delete cascade on update restrict", - }, - { - name: "without on delete and on update", - command: &contractsschema.Command{ - Index: "fk_users_role_id", - Columns: []string{"role_id", "user_id"}, - On: "roles", - References: []string{"id", "user_id"}, - }, - expectSql: "alter table `goravel_users` add constraint `fk_users_role_id` foreign key (`role_id`, `user_id`) references `goravel_roles` (`id`, `user_id`)", - }, - } - - for _, test := range tests { - s.Run(test.name, func() { - beforeEach() - - sql := s.grammar.CompileForeign(mockBlueprint, test.command) - s.Equal(test.expectSql, sql) - }) - } -} - -func (s *MysqlSuite) TestCompileIndex() { - var mockBlueprint *mocksschema.Blueprint - - beforeEach := func() { - mockBlueprint = mocksschema.NewBlueprint(s.T()) - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - } - - tests := []struct { - name string - command *contractsschema.Command - expectSql string - }{ - { - name: "with Algorithm", - command: &contractsschema.Command{ - Index: "fk_users_role_id", - Columns: []string{"role_id", "user_id"}, - Algorithm: "btree", - }, - expectSql: "alter table `goravel_users` add index `fk_users_role_id` using btree(`role_id`, `user_id`)", - }, - { - name: "without Algorithm", - command: &contractsschema.Command{ - Index: "fk_users_role_id", - Columns: []string{"role_id", "user_id"}, - }, - expectSql: "alter table `goravel_users` add index `fk_users_role_id`(`role_id`, `user_id`)", - }, - } - - for _, test := range tests { - s.Run(test.name, func() { - beforeEach() - - sql := s.grammar.CompileIndex(mockBlueprint, test.command) - s.Equal(test.expectSql, sql) - }) - } -} - -func (s *MysqlSuite) TestCompilePrimary() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - - s.Equal("alter table `goravel_users` add primary key (`role_id`, `user_id`)", s.grammar.CompilePrimary(mockBlueprint, &contractsschema.Command{ - Columns: []string{"role_id", "user_id"}, - })) -} - -func (s *MysqlSuite) TestCompileKey() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockBlueprint.EXPECT().GetTableName().Return("users").Twice() - - s.Equal("alter table `goravel_users` add unique `index`(`id`, `name`)", s.grammar.compileKey(mockBlueprint, &contractsschema.Command{ - Algorithm: "", - Columns: []string{"id", "name"}, - Index: "index", - }, "unique")) - - s.Equal("alter table `goravel_users` add unique `index` using btree(`id`, `name`)", s.grammar.compileKey(mockBlueprint, &contractsschema.Command{ - Algorithm: "btree", - Columns: []string{"id", "name"}, - Index: "index", - }, "unique")) -} - -func (s *MysqlSuite) TestGetColumns() { - mockColumn1 := mocksschema.NewColumnDefinition(s.T()) - mockColumn2 := mocksschema.NewColumnDefinition(s.T()) - mockBlueprint := mocksschema.NewBlueprint(s.T()) - - mockBlueprint.EXPECT().GetAddedColumns().Return([]contractsschema.ColumnDefinition{ - mockColumn1, mockColumn2, - }).Once() - mockBlueprint.EXPECT().HasCommand("primary").Return(false).Once() - - mockColumn1.EXPECT().GetName().Return("id").Once() - mockColumn1.EXPECT().GetType().Return("integer").Twice() - mockColumn1.EXPECT().GetDefault().Return(nil).Once() - mockColumn1.EXPECT().GetNullable().Return(false).Once() - mockColumn1.EXPECT().GetOnUpdate().Return(nil).Once() - mockColumn1.EXPECT().GetAutoIncrement().Return(true).Once() - mockColumn1.EXPECT().GetComment().Return("id").Once() - mockColumn1.EXPECT().GetUnsigned().Return(true).Once() - - mockColumn2.EXPECT().GetName().Return("name").Once() - mockColumn2.EXPECT().GetType().Return("string").Twice() - mockColumn2.EXPECT().GetDefault().Return("goravel").Twice() - mockColumn2.EXPECT().GetNullable().Return(true).Once() - mockColumn2.EXPECT().GetOnUpdate().Return(nil).Once() - mockColumn2.EXPECT().GetLength().Return(10).Once() - mockColumn2.EXPECT().GetComment().Return("name").Once() - mockColumn2.EXPECT().GetUnsigned().Return(false).Once() - - s.Equal([]string{"`id` int unsigned not null auto_increment primary key comment 'id'", "`name` varchar(10) null default 'goravel' comment 'name'"}, s.grammar.getColumns(mockBlueprint)) -} - -func (s *MysqlSuite) TestModifyDefault() { - var ( - mockBlueprint *mocksschema.Blueprint - mockColumn *mocksschema.ColumnDefinition - ) - - tests := []struct { - name string - setup func() - expectSql string - }{ - { - name: "without change and default is nil", - setup: func() { - mockColumn.EXPECT().GetDefault().Return(nil).Once() - }, - }, - { - name: "without change and default is not nil", - setup: func() { - mockColumn.EXPECT().GetDefault().Return("goravel").Twice() - }, - expectSql: " default 'goravel'", - }, - } - - for _, test := range tests { - s.Run(test.name, func() { - mockBlueprint = mocksschema.NewBlueprint(s.T()) - mockColumn = mocksschema.NewColumnDefinition(s.T()) - - test.setup() - - sql := s.grammar.ModifyDefault(mockBlueprint, mockColumn) - - s.Equal(test.expectSql, sql) - }) - } -} - -func (s *MysqlSuite) TestModifyNullable() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockColumn := mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetNullable().Return(true).Once() - - s.Equal(" null", s.grammar.ModifyNullable(mockBlueprint, mockColumn)) - - mockColumn.EXPECT().GetNullable().Return(false).Once() - - s.Equal(" not null", s.grammar.ModifyNullable(mockBlueprint, mockColumn)) -} - -func (s *MysqlSuite) TestModifyIncrement() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - - mockColumn := mocksschema.NewColumnDefinition(s.T()) - mockBlueprint.EXPECT().HasCommand("primary").Return(false).Once() - mockColumn.EXPECT().GetType().Return("bigInteger").Once() - mockColumn.EXPECT().GetAutoIncrement().Return(true).Once() - - s.Equal(" auto_increment primary key", s.grammar.ModifyIncrement(mockBlueprint, mockColumn)) -} - -func (s *MysqlSuite) TestModifyOnUpdate() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockColumn := mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetOnUpdate().Return(Expression("CURRENT_TIMESTAMP")).Once() - - s.Equal(" on update CURRENT_TIMESTAMP", s.grammar.ModifyOnUpdate(mockBlueprint, mockColumn)) - - mockColumn.EXPECT().GetOnUpdate().Return("CURRENT_TIMESTAMP").Once() - s.Equal(" on update CURRENT_TIMESTAMP", s.grammar.ModifyOnUpdate(mockBlueprint, mockColumn)) - - mockColumn.EXPECT().GetOnUpdate().Return("").Once() - s.Empty(s.grammar.ModifyOnUpdate(mockBlueprint, mockColumn)) - - mockColumn.EXPECT().GetOnUpdate().Return(nil).Once() - s.Empty(s.grammar.ModifyOnUpdate(mockBlueprint, mockColumn)) -} - -func (s *MysqlSuite) TestTypeDateTime() { - mockColumn := mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetPrecision().Return(3).Once() - mockColumn.EXPECT().GetUseCurrent().Return(true).Once() - mockColumn.EXPECT().Default(Expression("CURRENT_TIMESTAMP(3)")).Return(mockColumn).Once() - mockColumn.EXPECT().GetUseCurrentOnUpdate().Return(true).Once() - mockColumn.EXPECT().OnUpdate(Expression("CURRENT_TIMESTAMP(3)")).Return(mockColumn).Once() - s.Equal("datetime(3)", s.grammar.TypeDateTime(mockColumn)) - - mockColumn = mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetPrecision().Return(0).Once() - mockColumn.EXPECT().GetUseCurrent().Return(false).Once() - mockColumn.EXPECT().GetUseCurrentOnUpdate().Return(false).Once() - s.Equal("datetime", s.grammar.TypeDateTime(mockColumn)) -} - -func (s *MysqlSuite) TestTypeDecimal() { - mockColumn := mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetTotal().Return(4).Once() - mockColumn.EXPECT().GetPlaces().Return(2).Once() - - s.Equal("decimal(4, 2)", s.grammar.TypeDecimal(mockColumn)) -} - -func (s *MysqlSuite) TestTypeEnum() { - mockColumn := mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetAllowed().Return([]any{"a", "b"}).Once() - - s.Equal(`enum('a', 'b')`, s.grammar.TypeEnum(mockColumn)) -} - -func (s *MysqlSuite) TestTypeFloat() { - mockColumn := mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetPrecision().Return(0).Once() - - s.Equal("float", s.grammar.TypeFloat(mockColumn)) - - mockColumn.EXPECT().GetPrecision().Return(2).Once() - - s.Equal("float(2)", s.grammar.TypeFloat(mockColumn)) -} - -func (s *MysqlSuite) TestTypeString() { - mockColumn1 := mocksschema.NewColumnDefinition(s.T()) - mockColumn1.EXPECT().GetLength().Return(100).Once() - - s.Equal("varchar(100)", s.grammar.TypeString(mockColumn1)) - - mockColumn2 := mocksschema.NewColumnDefinition(s.T()) - mockColumn2.EXPECT().GetLength().Return(0).Once() - - s.Equal("varchar(255)", s.grammar.TypeString(mockColumn2)) -} - -func (s *MysqlSuite) TestTypeTimestamp() { - mockColumn := mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetPrecision().Return(3).Once() - mockColumn.EXPECT().GetUseCurrent().Return(true).Once() - mockColumn.EXPECT().Default(Expression("CURRENT_TIMESTAMP(3)")).Return(mockColumn).Once() - mockColumn.EXPECT().GetUseCurrentOnUpdate().Return(true).Once() - mockColumn.EXPECT().OnUpdate(Expression("CURRENT_TIMESTAMP(3)")).Return(mockColumn).Once() - s.Equal("timestamp(3)", s.grammar.TypeTimestamp(mockColumn)) - - mockColumn = mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetPrecision().Return(0).Once() - mockColumn.EXPECT().GetUseCurrent().Return(false).Once() - mockColumn.EXPECT().GetUseCurrentOnUpdate().Return(false).Once() - s.Equal("timestamp", s.grammar.TypeTimestamp(mockColumn)) -} diff --git a/database/schema/grammars/sqlite.go b/database/schema/grammars/sqlite.go deleted file mode 100644 index 128524fcc..000000000 --- a/database/schema/grammars/sqlite.go +++ /dev/null @@ -1,441 +0,0 @@ -package grammars - -import ( - "fmt" - "slices" - "strings" - - "github.com/spf13/cast" - - contractsdatabase "github.com/goravel/framework/contracts/database" - "github.com/goravel/framework/contracts/database/schema" - "github.com/goravel/framework/contracts/log" - "github.com/goravel/framework/support/collect" -) - -type Sqlite struct { - attributeCommands []string - log log.Log - modifiers []func(schema.Blueprint, schema.ColumnDefinition) string - serials []string - tablePrefix string - wrap *Wrap -} - -func NewSqlite(log log.Log, tablePrefix string) *Sqlite { - sqlite := &Sqlite{ - attributeCommands: []string{}, - log: log, - serials: []string{"bigInteger", "integer", "mediumInteger", "smallInteger", "tinyInteger"}, - tablePrefix: tablePrefix, - wrap: NewWrap(contractsdatabase.DriverSqlite, tablePrefix), - } - sqlite.modifiers = []func(schema.Blueprint, schema.ColumnDefinition) string{ - sqlite.ModifyDefault, - sqlite.ModifyIncrement, - sqlite.ModifyNullable, - } - - return sqlite -} - -func (r *Sqlite) CompileAdd(blueprint schema.Blueprint, command *schema.Command) string { - return fmt.Sprintf("alter table %s add column %s", r.wrap.Table(blueprint.GetTableName()), r.getColumn(blueprint, command.Column)) -} - -func (r *Sqlite) CompileChange(blueprint schema.Blueprint, command *schema.Command) []string { - return nil -} - -func (r *Sqlite) CompileColumns(schema, table string) string { - return fmt.Sprintf( - `select name, type, not "notnull" as "nullable", dflt_value as "default", pk as "primary", hidden as "extra" `+ - "from pragma_table_xinfo(%s) order by cid asc", r.wrap.Quote(strings.ReplaceAll(table, ".", "__"))) -} - -func (r *Sqlite) CompileComment(blueprint schema.Blueprint, command *schema.Command) string { - return "" -} - -func (r *Sqlite) CompileCreate(blueprint schema.Blueprint) string { - return fmt.Sprintf("create table %s (%s%s%s)", - r.wrap.Table(blueprint.GetTableName()), - strings.Join(r.getColumns(blueprint), ", "), - r.addForeignKeys(getCommandsByName(blueprint.GetCommands(), "foreign")), - r.addPrimaryKeys(getCommandByName(blueprint.GetCommands(), "primary"))) -} - -func (r *Sqlite) CompileDefault(_ schema.Blueprint, _ *schema.Command) string { - return "" -} - -func (r *Sqlite) CompileDisableWriteableSchema() string { - return r.pragma("writable_schema", "0") -} - -func (r *Sqlite) CompileDrop(blueprint schema.Blueprint) string { - return fmt.Sprintf("drop table %s", r.wrap.Table(blueprint.GetTableName())) -} - -func (r *Sqlite) CompileDropAllDomains(domains []string) string { - return "" -} - -func (r *Sqlite) CompileDropAllTables(tables []string) string { - return "delete from sqlite_master where type in ('table', 'index', 'trigger')" -} - -func (r *Sqlite) CompileDropAllTypes(types []string) string { - return "" -} - -func (r *Sqlite) CompileDropAllViews(views []string) string { - return "delete from sqlite_master where type in ('view')" -} - -func (r *Sqlite) CompileDropColumn(blueprint schema.Blueprint, command *schema.Command) []string { - // TODO check Sqlite 3.35 - table := r.wrap.Table(blueprint.GetTableName()) - columns := r.wrap.PrefixArray("drop column", r.wrap.Columns(command.Columns)) - - return collect.Map(columns, func(column string, _ int) string { - return fmt.Sprintf("alter table %s %s", table, column) - }) -} - -func (r *Sqlite) CompileDropForeign(_ schema.Blueprint, _ *schema.Command) string { - return "" -} - -func (r *Sqlite) CompileDropFullText(_ schema.Blueprint, _ *schema.Command) string { - return "" -} - -func (r *Sqlite) CompileDropIfExists(blueprint schema.Blueprint) string { - return fmt.Sprintf("drop table if exists %s", r.wrap.Table(blueprint.GetTableName())) -} - -func (r *Sqlite) CompileDropIndex(_ schema.Blueprint, command *schema.Command) string { - return fmt.Sprintf("drop index %s", r.wrap.Column(command.Index)) -} - -func (r *Sqlite) CompileDropPrimary(_ schema.Blueprint, _ *schema.Command) string { - return "" -} - -func (r *Sqlite) CompileDropUnique(blueprint schema.Blueprint, command *schema.Command) string { - return r.CompileDropIndex(blueprint, command) -} - -func (r *Sqlite) CompileEnableWriteableSchema() string { - return r.pragma("writable_schema", "1") -} - -func (r *Sqlite) CompileForeign(_ schema.Blueprint, _ *schema.Command) string { - return "" -} - -func (r *Sqlite) CompileForeignKeys(_, table string) string { - return fmt.Sprintf( - `SELECT - GROUP_CONCAT("from") AS columns, - "table" AS foreign_table, - GROUP_CONCAT("to") AS foreign_columns, - on_update, - on_delete - FROM ( - SELECT * FROM pragma_foreign_key_list(%s) - ORDER BY id DESC, seq - ) - GROUP BY id, "table", on_update, on_delete`, - r.wrap.Quote(strings.ReplaceAll(table, ".", "__")), - ) -} - -func (r *Sqlite) CompileFullText(_ schema.Blueprint, _ *schema.Command) string { - return "" -} - -func (r *Sqlite) CompileIndex(blueprint schema.Blueprint, command *schema.Command) string { - return fmt.Sprintf("create index %s on %s (%s)", - r.wrap.Column(command.Index), - r.wrap.Table(blueprint.GetTableName()), - r.wrap.Columnize(command.Columns), - ) -} - -func (r *Sqlite) CompileIndexes(_, table string) string { - quotedTable := r.wrap.Quote(strings.ReplaceAll(table, ".", "__")) - - return fmt.Sprintf( - `select 'primary' as name, group_concat(col) as columns, 1 as "unique", 1 as "primary" `+ - `from (select name as col from pragma_table_info(%s) where pk > 0 order by pk, cid) group by name `+ - `union select name, group_concat(col) as columns, "unique", origin = 'pk' as "primary" `+ - `from (select il.*, ii.name as col from pragma_index_list(%s) il, pragma_index_info(il.name) ii order by il.seq, ii.seqno) `+ - `group by name, "unique", "primary"`, - quotedTable, - r.wrap.Quote(table), - ) -} - -func (r *Sqlite) CompilePrimary(_ schema.Blueprint, _ *schema.Command) string { - return "" -} - -func (r *Sqlite) CompileRebuild() string { - return "vacuum" -} - -func (r *Sqlite) CompileRename(blueprint schema.Blueprint, command *schema.Command) string { - return fmt.Sprintf("alter table %s rename to %s", r.wrap.Table(blueprint.GetTableName()), r.wrap.Table(command.To)) -} - -func (r *Sqlite) CompileRenameIndex(s schema.Schema, blueprint schema.Blueprint, command *schema.Command) []string { - indexes, err := s.GetIndexes(blueprint.GetTableName()) - if err != nil { - r.log.Errorf("failed to get %s indexes: %v", blueprint.GetTableName(), err) - return nil - } - - indexes = collect.Filter(indexes, func(index schema.Index, _ int) bool { - return index.Name == command.From - }) - - if len(indexes) == 0 { - r.log.Warningf("index %s does not exist", command.From) - return nil - } - if indexes[0].Primary { - r.log.Warning("SQLite does not support altering primary keys") - return nil - } - if indexes[0].Unique { - return []string{ - r.CompileDropUnique(blueprint, &schema.Command{ - Index: indexes[0].Name, - }), - r.CompileUnique(blueprint, &schema.Command{ - Index: command.To, - Columns: indexes[0].Columns, - }), - } - } - - return []string{ - r.CompileDropIndex(blueprint, &schema.Command{ - Index: indexes[0].Name, - }), - r.CompileIndex(blueprint, &schema.Command{ - Index: command.To, - Columns: indexes[0].Columns, - }), - } -} - -func (r *Sqlite) CompileTables(database string) string { - return "select name from sqlite_master where type = 'table' and name not like 'sqlite_%' order by name" -} - -func (r *Sqlite) CompileTypes() string { - return "" -} - -func (r *Sqlite) CompileUnique(blueprint schema.Blueprint, command *schema.Command) string { - return fmt.Sprintf("create unique index %s on %s (%s)", - r.wrap.Column(command.Index), - r.wrap.Table(blueprint.GetTableName()), - r.wrap.Columnize(command.Columns)) -} - -func (r *Sqlite) CompileViews(database string) string { - return "select name, sql as definition from sqlite_master where type = 'view' order by name" -} - -func (r *Sqlite) GetAttributeCommands() []string { - return r.attributeCommands -} - -func (r *Sqlite) GetModifiers() []func(blueprint schema.Blueprint, column schema.ColumnDefinition) string { - return r.modifiers -} - -func (r *Sqlite) ModifyDefault(blueprint schema.Blueprint, column schema.ColumnDefinition) string { - if column.GetDefault() != nil { - return fmt.Sprintf(" default %s", getDefaultValue(column.GetDefault())) - } - - return "" -} - -func (r *Sqlite) ModifyNullable(blueprint schema.Blueprint, column schema.ColumnDefinition) string { - if column.GetNullable() { - return " null" - } else { - return " not null" - } -} - -func (r *Sqlite) ModifyIncrement(blueprint schema.Blueprint, column schema.ColumnDefinition) string { - if slices.Contains(r.serials, column.GetType()) && column.GetAutoIncrement() { - return " primary key autoincrement" - } - - return "" -} - -func (r *Sqlite) TypeBigInteger(column schema.ColumnDefinition) string { - return "integer" -} - -func (r *Sqlite) TypeChar(column schema.ColumnDefinition) string { - return "varchar" -} - -func (r *Sqlite) TypeDate(column schema.ColumnDefinition) string { - return "date" -} - -func (r *Sqlite) TypeDateTime(column schema.ColumnDefinition) string { - return r.TypeTimestamp(column) -} - -func (r *Sqlite) TypeDateTimeTz(column schema.ColumnDefinition) string { - return r.TypeDateTime(column) -} - -func (r *Sqlite) TypeDecimal(column schema.ColumnDefinition) string { - return "numeric" -} - -func (r *Sqlite) TypeDouble(column schema.ColumnDefinition) string { - return "double" -} - -func (r *Sqlite) TypeEnum(column schema.ColumnDefinition) string { - return fmt.Sprintf(`varchar check ("%s" in (%s))`, column.GetName(), strings.Join(r.wrap.Quotes(cast.ToStringSlice(column.GetAllowed())), ", ")) -} - -func (r *Sqlite) TypeFloat(column schema.ColumnDefinition) string { - return "float" -} - -func (r *Sqlite) TypeInteger(column schema.ColumnDefinition) string { - return "integer" -} - -func (r *Sqlite) TypeJson(column schema.ColumnDefinition) string { - return "text" -} - -func (r *Sqlite) TypeJsonb(column schema.ColumnDefinition) string { - return "text" -} - -func (r *Sqlite) TypeLongText(column schema.ColumnDefinition) string { - return "text" -} - -func (r *Sqlite) TypeMediumInteger(column schema.ColumnDefinition) string { - return "integer" -} - -func (r *Sqlite) TypeMediumText(column schema.ColumnDefinition) string { - return "text" -} - -func (r *Sqlite) TypeSmallInteger(column schema.ColumnDefinition) string { - return "integer" -} - -func (r *Sqlite) TypeString(column schema.ColumnDefinition) string { - return "varchar" -} - -func (r *Sqlite) TypeText(column schema.ColumnDefinition) string { - return "text" -} - -func (r *Sqlite) TypeTime(column schema.ColumnDefinition) string { - return "time" -} - -func (r *Sqlite) TypeTimeTz(column schema.ColumnDefinition) string { - return r.TypeTime(column) -} - -func (r *Sqlite) TypeTimestamp(column schema.ColumnDefinition) string { - if column.GetUseCurrent() { - column.Default(Expression("CURRENT_TIMESTAMP")) - } - - return "datetime" -} - -func (r *Sqlite) TypeTimestampTz(column schema.ColumnDefinition) string { - return r.TypeTimestamp(column) -} - -func (r *Sqlite) TypeTinyInteger(column schema.ColumnDefinition) string { - return "integer" -} - -func (r *Sqlite) TypeTinyText(column schema.ColumnDefinition) string { - return "text" -} - -func (r *Sqlite) addForeignKeys(commands []*schema.Command) string { - var sql string - - for _, command := range commands { - sql += r.getForeignKey(command) - } - - return sql -} - -func (r *Sqlite) addPrimaryKeys(command *schema.Command) string { - if command == nil { - return "" - } - - return fmt.Sprintf(", primary key (%s)", r.wrap.Columnize(command.Columns)) -} - -func (r *Sqlite) getColumns(blueprint schema.Blueprint) []string { - var columns []string - for _, column := range blueprint.GetAddedColumns() { - columns = append(columns, r.getColumn(blueprint, column)) - } - - return columns -} - -func (r *Sqlite) getColumn(blueprint schema.Blueprint, column schema.ColumnDefinition) string { - sql := fmt.Sprintf("%s %s", r.wrap.Column(column.GetName()), getType(r, column)) - - for _, modifier := range r.modifiers { - sql += modifier(blueprint, column) - } - - return sql -} - -func (r *Sqlite) getForeignKey(command *schema.Command) string { - sql := fmt.Sprintf(", foreign key(%s) references %s(%s)", - r.wrap.Columnize(command.Columns), - r.wrap.Table(command.On), - r.wrap.Columnize(command.References)) - - if command.OnDelete != "" { - sql += " on delete " + command.OnDelete - } - if command.OnUpdate != "" { - sql += " on update " + command.OnUpdate - } - - return sql -} - -func (r *Sqlite) pragma(name, value string) string { - return fmt.Sprintf("pragma %s = %s", name, value) -} diff --git a/database/schema/grammars/sqlite_test.go b/database/schema/grammars/sqlite_test.go deleted file mode 100644 index 0e54d7757..000000000 --- a/database/schema/grammars/sqlite_test.go +++ /dev/null @@ -1,367 +0,0 @@ -package grammars - -import ( - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/suite" - - contractsschema "github.com/goravel/framework/contracts/database/schema" - mocksschema "github.com/goravel/framework/mocks/database/schema" - mockslog "github.com/goravel/framework/mocks/log" -) - -type SqliteSuite struct { - suite.Suite - grammar *Sqlite - mockLog *mockslog.Log -} - -func TestSqliteSuite(t *testing.T) { - suite.Run(t, &SqliteSuite{}) -} - -func (s *SqliteSuite) SetupTest() { - s.mockLog = mockslog.NewLog(s.T()) - - s.grammar = NewSqlite(s.mockLog, "goravel_") -} - -func (s *SqliteSuite) TestAddForeignKeys() { - commands := []*contractsschema.Command{ - { - Columns: []string{"role_id", "permission_id"}, - On: "roles", - References: []string{"id", "user_id"}, - OnDelete: "cascade", - OnUpdate: "restrict", - }, - { - Columns: []string{"permission_id", "role_id"}, - On: "permissions", - References: []string{"id", "user_id"}, - }, - } - - s.Equal(`, foreign key("role_id", "permission_id") references "goravel_roles"("id", "user_id") on delete cascade on update restrict, foreign key("permission_id", "role_id") references "goravel_permissions"("id", "user_id")`, s.grammar.addForeignKeys(commands)) -} - -func (s *SqliteSuite) TestCompileAdd() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockColumn := mocksschema.NewColumnDefinition(s.T()) - - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - mockColumn.EXPECT().GetName().Return("name").Once() - mockColumn.EXPECT().GetType().Return("string").Twice() - mockColumn.EXPECT().GetDefault().Return("goravel").Twice() - mockColumn.EXPECT().GetNullable().Return(false).Once() - - sql := s.grammar.CompileAdd(mockBlueprint, &contractsschema.Command{ - Column: mockColumn, - }) - - s.Equal(`alter table "goravel_users" add column "name" varchar default 'goravel' not null`, sql) -} - -func (s *SqliteSuite) TestCompileCreate() { - mockColumn1 := mocksschema.NewColumnDefinition(s.T()) - mockColumn2 := mocksschema.NewColumnDefinition(s.T()) - mockBlueprint := mocksschema.NewBlueprint(s.T()) - - // sqlite.go::CompileCreate - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - // utils.go::getColumns - mockBlueprint.EXPECT().GetAddedColumns().Return([]contractsschema.ColumnDefinition{ - mockColumn1, mockColumn2, - }).Once() - // utils.go::getColumns - mockColumn1.EXPECT().GetName().Return("id").Once() - // utils.go::getType - mockColumn1.EXPECT().GetType().Return("integer").Once() - // sqlite.go::TypeInteger - mockColumn1.EXPECT().GetAutoIncrement().Return(true).Once() - // sqlite.go::ModifyDefault - mockColumn1.EXPECT().GetDefault().Return(nil).Once() - // sqlite.go::ModifyIncrement - mockColumn1.EXPECT().GetType().Return("integer").Once() - // sqlite.go::ModifyNullable - mockColumn1.EXPECT().GetNullable().Return(false).Once() - - // utils.go::getColumns - mockColumn2.EXPECT().GetName().Return("name").Once() - // utils.go::getType - mockColumn2.EXPECT().GetType().Return("string").Once() - // sqlite.go::ModifyDefault - mockColumn2.EXPECT().GetDefault().Return(nil).Once() - // sqlite.go::ModifyIncrement - mockColumn2.EXPECT().GetType().Return("string").Once() - // sqlite.go::ModifyNullable - mockColumn2.EXPECT().GetNullable().Return(true).Once() - - // sqlite.go::CompileCreate - mockBlueprint.EXPECT().GetCommands().Return([]*contractsschema.Command{ - { - Name: "primary", - Columns: []string{"id"}, - }, - { - Name: "foreign", - Columns: []string{"role_id", "permission_id"}, - On: "roles", - References: []string{"id"}, - OnDelete: "cascade", - OnUpdate: "restrict", - }, - { - Name: "foreign", - Columns: []string{"permission_id", "role_id"}, - On: "permissions", - References: []string{"id"}, - OnDelete: "cascade", - OnUpdate: "restrict", - }, - }).Twice() - - s.Equal(`create table "goravel_users" ("id" integer primary key autoincrement not null, "name" varchar null, foreign key("role_id", "permission_id") references "goravel_roles"("id") on delete cascade on update restrict, foreign key("permission_id", "role_id") references "goravel_permissions"("id") on delete cascade on update restrict, primary key ("id"))`, - s.grammar.CompileCreate(mockBlueprint)) -} - -func (s *SqliteSuite) TestCompileDropColumn() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - - s.Equal([]string{ - `alter table "goravel_users" drop column "id"`, - `alter table "goravel_users" drop column "name"`, - }, s.grammar.CompileDropColumn(mockBlueprint, &contractsschema.Command{ - Name: "name", - Columns: []string{"id", "name"}, - })) -} - -func (s *SqliteSuite) TestCompileDropIfExists() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - - s.Equal(`drop table if exists "goravel_users"`, s.grammar.CompileDropIfExists(mockBlueprint)) -} - -func (s *SqliteSuite) TestCompileIndex() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - command := &contractsschema.Command{ - Index: "users", - Columns: []string{"role_id", "permission_id"}, - } - - s.Equal(`create index "users" on "goravel_users" ("role_id", "permission_id")`, s.grammar.CompileIndex(mockBlueprint, command)) -} - -func (s *SqliteSuite) TestCompileRenameIndex() { - var ( - mockSchema *mocksschema.Schema - mockBlueprint *mocksschema.Blueprint - ) - - beforeEach := func() { - mockSchema = mocksschema.NewSchema(s.T()) - mockBlueprint = mocksschema.NewBlueprint(s.T()) - } - - tests := []struct { - name string - command *contractsschema.Command - setup func() - expect []string - }{ - { - name: "failed to get indexes", - setup: func() { - tableName := "users" - mockBlueprint.EXPECT().GetTableName().Return(tableName).Twice() - mockSchema.EXPECT().GetIndexes(tableName).Return(nil, assert.AnError).Once() - s.mockLog.EXPECT().Errorf("failed to get %s indexes: %v", tableName, assert.AnError).Once() - }, - }, - { - name: "index does not exist", - command: &contractsschema.Command{ - From: "users", - }, - setup: func() { - tableName := "users" - mockBlueprint.EXPECT().GetTableName().Return(tableName).Once() - mockSchema.EXPECT().GetIndexes(tableName).Return([]contractsschema.Index{ - { - Name: "admins", - }, - }, nil).Once() - s.mockLog.EXPECT().Warningf("index %s does not exist", "users").Once() - }, - }, - { - name: "index is primary", - command: &contractsschema.Command{ - From: "users", - }, - setup: func() { - tableName := "users" - mockBlueprint.EXPECT().GetTableName().Return(tableName).Once() - mockSchema.EXPECT().GetIndexes(tableName).Return([]contractsschema.Index{ - { - Name: "users", - Primary: true, - }, - }, nil).Once() - s.mockLog.EXPECT().Warning("SQLite does not support altering primary keys").Once() - }, - }, - { - name: "index is unique", - command: &contractsschema.Command{ - From: "users", - To: "admins", - }, - setup: func() { - tableName := "users" - mockBlueprint.EXPECT().GetTableName().Return(tableName).Twice() - mockSchema.EXPECT().GetIndexes(tableName).Return([]contractsschema.Index{ - { - Columns: []string{"role_id", "permission_id"}, - Name: "users", - Unique: true, - }, - }, nil).Once() - }, - expect: []string{ - `drop index "users"`, - `create unique index "admins" on "goravel_users" ("role_id", "permission_id")`, - }, - }, - { - name: "success", - command: &contractsschema.Command{ - From: "users", - To: "admins", - }, - setup: func() { - tableName := "users" - mockBlueprint.EXPECT().GetTableName().Return(tableName).Twice() - mockSchema.EXPECT().GetIndexes(tableName).Return([]contractsschema.Index{ - { - Columns: []string{"role_id", "permission_id"}, - Name: "users", - }, - }, nil).Once() - }, - expect: []string{ - `drop index "users"`, - `create index "admins" on "goravel_users" ("role_id", "permission_id")`, - }, - }, - } - - for _, test := range tests { - s.Run(test.name, func() { - beforeEach() - test.setup() - - s.Equal(test.expect, s.grammar.CompileRenameIndex(mockSchema, mockBlueprint, test.command)) - }) - } -} - -func (s *SqliteSuite) TestGetColumns() { - mockColumn1 := mocksschema.NewColumnDefinition(s.T()) - mockColumn2 := mocksschema.NewColumnDefinition(s.T()) - mockBlueprint := mocksschema.NewBlueprint(s.T()) - - mockBlueprint.EXPECT().GetAddedColumns().Return([]contractsschema.ColumnDefinition{ - mockColumn1, mockColumn2, - }).Once() - - mockColumn1.EXPECT().GetName().Return("id").Once() - mockColumn1.EXPECT().GetType().Return("integer").Twice() - mockColumn1.EXPECT().GetDefault().Return(nil).Once() - mockColumn1.EXPECT().GetNullable().Return(false).Once() - mockColumn1.EXPECT().GetAutoIncrement().Return(true).Once() - - mockColumn2.EXPECT().GetName().Return("name").Once() - mockColumn2.EXPECT().GetType().Return("string").Twice() - mockColumn2.EXPECT().GetDefault().Return("goravel").Twice() - mockColumn2.EXPECT().GetNullable().Return(true).Once() - - s.Equal([]string{"\"id\" integer primary key autoincrement not null", "\"name\" varchar default 'goravel' null"}, s.grammar.getColumns(mockBlueprint)) -} - -func (s *SqliteSuite) TestModifyDefault() { - var ( - mockBlueprint *mocksschema.Blueprint - mockColumn *mocksschema.ColumnDefinition - ) - - tests := []struct { - name string - setup func() - expectSql string - }{ - { - name: "without change and default is nil", - setup: func() { - mockColumn.EXPECT().GetDefault().Return(nil).Once() - }, - }, - { - name: "without change and default is not nil", - setup: func() { - mockColumn.EXPECT().GetDefault().Return("goravel").Twice() - }, - expectSql: " default 'goravel'", - }, - } - - for _, test := range tests { - s.Run(test.name, func() { - mockBlueprint = mocksschema.NewBlueprint(s.T()) - mockColumn = mocksschema.NewColumnDefinition(s.T()) - - test.setup() - - sql := s.grammar.ModifyDefault(mockBlueprint, mockColumn) - - s.Equal(test.expectSql, sql) - }) - } -} - -func (s *SqliteSuite) TestModifyNullable() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - - mockColumn := mocksschema.NewColumnDefinition(s.T()) - - mockColumn.EXPECT().GetNullable().Return(true).Once() - - s.Equal(" null", s.grammar.ModifyNullable(mockBlueprint, mockColumn)) - - mockColumn.EXPECT().GetNullable().Return(false).Once() - - s.Equal(" not null", s.grammar.ModifyNullable(mockBlueprint, mockColumn)) -} - -func (s *SqliteSuite) TestModifyIncrement() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - - mockColumn := mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetType().Return("bigInteger").Once() - mockColumn.EXPECT().GetAutoIncrement().Return(true).Once() - - s.Equal(" primary key autoincrement", s.grammar.ModifyIncrement(mockBlueprint, mockColumn)) -} - -func (s *SqliteSuite) TestTypeEnum() { - mockColumn := mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetName().Return("a").Once() - mockColumn.EXPECT().GetAllowed().Return([]any{"a", "b"}).Once() - - s.Equal(`varchar check ("a" in ('a', 'b'))`, s.grammar.TypeEnum(mockColumn)) -} diff --git a/database/schema/grammars/sqlserver.go b/database/schema/grammars/sqlserver.go deleted file mode 100644 index 595ca0dc7..000000000 --- a/database/schema/grammars/sqlserver.go +++ /dev/null @@ -1,474 +0,0 @@ -package grammars - -import ( - "fmt" - "slices" - "strings" - - "github.com/spf13/cast" - - "github.com/goravel/framework/contracts/database" - "github.com/goravel/framework/contracts/database/schema" - "github.com/goravel/framework/database/schema/constants" -) - -type Sqlserver struct { - attributeCommands []string - modifiers []func(schema.Blueprint, schema.ColumnDefinition) string - serials []string - wrap *Wrap -} - -func NewSqlserver(tablePrefix string) *Sqlserver { - sqlserver := &Sqlserver{ - attributeCommands: []string{constants.CommandComment, constants.CommandDefault}, - serials: []string{"bigInteger", "integer", "mediumInteger", "smallInteger", "tinyInteger"}, - wrap: NewWrap(database.DriverSqlserver, tablePrefix), - } - sqlserver.modifiers = []func(schema.Blueprint, schema.ColumnDefinition) string{ - sqlserver.ModifyDefault, - sqlserver.ModifyIncrement, - sqlserver.ModifyNullable, - } - - return sqlserver -} - -func (r *Sqlserver) CompileAdd(blueprint schema.Blueprint, command *schema.Command) string { - return fmt.Sprintf("alter table %s add %s", r.wrap.Table(blueprint.GetTableName()), r.getColumn(blueprint, command.Column)) -} - -func (r *Sqlserver) CompileChange(blueprint schema.Blueprint, command *schema.Command) []string { - return []string{ - r.CompileDropDefaultConstraint(blueprint, command), - fmt.Sprintf("alter table %s alter column %s", r.wrap.Table(blueprint.GetTableName()), r.getColumn(blueprint, command.Column)), - } -} - -func (r *Sqlserver) CompileColumns(schema, table string) string { - newSchema := "schema_name()" - if schema != "" { - newSchema = r.wrap.Quote(schema) - } - - return fmt.Sprintf( - "select col.name, type.name as type_name, "+ - "col.max_length as length, col.precision as precision, col.scale as places, "+ - "col.is_nullable as nullable, def.definition as [default], "+ - "col.is_identity as autoincrement, col.collation_name as collation, "+ - "com.definition as [expression], is_persisted as [persisted], "+ - "cast(prop.value as nvarchar(max)) as comment "+ - "from sys.columns as col "+ - "join sys.types as type on col.user_type_id = type.user_type_id "+ - "join sys.objects as obj on col.object_id = obj.object_id "+ - "join sys.schemas as scm on obj.schema_id = scm.schema_id "+ - "left join sys.default_constraints def on col.default_object_id = def.object_id and col.object_id = def.parent_object_id "+ - "left join sys.extended_properties as prop on obj.object_id = prop.major_id and col.column_id = prop.minor_id and prop.name = 'MS_Description' "+ - "left join sys.computed_columns as com on col.column_id = com.column_id and col.object_id = com.object_id "+ - "where obj.type in ('U', 'V') and obj.name = %s and scm.name = %s "+ - "order by col.column_id", r.wrap.Quote(table), newSchema) -} - -func (r *Sqlserver) CompileComment(_ schema.Blueprint, _ *schema.Command) string { - return "" -} - -func (r *Sqlserver) CompileCreate(blueprint schema.Blueprint) string { - return fmt.Sprintf("create table %s (%s)", r.wrap.Table(blueprint.GetTableName()), strings.Join(r.getColumns(blueprint), ", ")) -} - -func (r *Sqlserver) CompileDefault(blueprint schema.Blueprint, command *schema.Command) string { - if command.Column.IsChange() && command.Column.GetDefault() != nil { - return fmt.Sprintf("alter table %s add default %s for %s", - r.wrap.Table(blueprint.GetTableName()), - getDefaultValue(command.Column.GetDefault()), - r.wrap.Column(command.Column.GetName()), - ) - } - - return "" -} - -func (r *Sqlserver) CompileDrop(blueprint schema.Blueprint) string { - return fmt.Sprintf("drop table %s", r.wrap.Table(blueprint.GetTableName())) -} - -func (r *Sqlserver) CompileDropAllDomains(_ []string) string { - return "" -} - -func (r *Sqlserver) CompileDropAllForeignKeys() string { - return `DECLARE @sql NVARCHAR(MAX) = N''; - SELECT @sql += 'ALTER TABLE ' - + QUOTENAME(OBJECT_SCHEMA_NAME(parent_object_id)) + '.' + + QUOTENAME(OBJECT_NAME(parent_object_id)) - + ' DROP CONSTRAINT ' + QUOTENAME(name) + ';' - FROM sys.foreign_keys; - - EXEC sp_executesql @sql;` -} - -func (r *Sqlserver) CompileDropAllTables(_ []string) string { - return "EXEC sp_msforeachtable 'DROP TABLE ?'" -} - -func (r *Sqlserver) CompileDropAllTypes(_ []string) string { - return "" -} - -func (r *Sqlserver) CompileDropAllViews(_ []string) string { - return `DECLARE @sql NVARCHAR(MAX) = N''; - SELECT @sql += 'DROP VIEW ' + QUOTENAME(OBJECT_SCHEMA_NAME(object_id)) + '.' + QUOTENAME(name) + ';' - FROM sys.views; - - EXEC sp_executesql @sql;` -} - -func (r *Sqlserver) CompileDropColumn(blueprint schema.Blueprint, command *schema.Command) []string { - columns := r.wrap.Columns(command.Columns) - - dropExistingConstraintsSql := r.CompileDropDefaultConstraint(blueprint, command) - - return []string{ - fmt.Sprintf("%s alter table %s drop column %s", dropExistingConstraintsSql, r.wrap.Table(blueprint.GetTableName()), strings.Join(columns, ", ")), - } -} - -func (r *Sqlserver) CompileDropDefaultConstraint(blueprint schema.Blueprint, command *schema.Command) string { - columns := fmt.Sprintf("'%s'", strings.Join(command.Columns, "','")) - if command.Column != nil && command.Column.IsChange() { - columns = fmt.Sprintf("'%s'", command.Column.GetName()) - } - table := r.wrap.Table(blueprint.GetTableName()) - tableName := r.wrap.Quote(table) - - return fmt.Sprintf("DECLARE @sql NVARCHAR(MAX) = '';"+ - "SELECT @sql += 'ALTER TABLE %s DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' "+ - "FROM sys.columns "+ - "WHERE [object_id] = OBJECT_ID(%s) AND [name] in (%s) AND [default_object_id] <> 0;"+ - "EXEC(@sql);", table, tableName, columns) -} - -func (r *Sqlserver) CompileDropForeign(blueprint schema.Blueprint, command *schema.Command) string { - return fmt.Sprintf("alter table %s drop constraint %s", r.wrap.Table(blueprint.GetTableName()), r.wrap.Column(command.Index)) -} - -func (r *Sqlserver) CompileDropFullText(_ schema.Blueprint, _ *schema.Command) string { - return "" -} - -func (r *Sqlserver) CompileDropIfExists(blueprint schema.Blueprint) string { - table := r.wrap.Table(blueprint.GetTableName()) - - return fmt.Sprintf("if object_id(%s, 'U') is not null drop table %s", r.wrap.Quote(table), table) -} - -func (r *Sqlserver) CompileDropIndex(blueprint schema.Blueprint, command *schema.Command) string { - return fmt.Sprintf("drop index %s on %s", r.wrap.Column(command.Index), r.wrap.Table(blueprint.GetTableName())) -} - -func (r *Sqlserver) CompileDropPrimary(blueprint schema.Blueprint, command *schema.Command) string { - return fmt.Sprintf("alter table %s drop constraint %s", r.wrap.Table(blueprint.GetTableName()), r.wrap.Column(command.Index)) -} - -func (r *Sqlserver) CompileDropUnique(blueprint schema.Blueprint, command *schema.Command) string { - return r.CompileDropIndex(blueprint, command) -} - -func (r *Sqlserver) CompileForeign(blueprint schema.Blueprint, command *schema.Command) string { - sql := fmt.Sprintf("alter table %s add constraint %s foreign key (%s) references %s (%s)", - r.wrap.Table(blueprint.GetTableName()), - r.wrap.Column(command.Index), - r.wrap.Columnize(command.Columns), - r.wrap.Table(command.On), - r.wrap.Columnize(command.References)) - if command.OnDelete != "" { - sql += " on delete " + command.OnDelete - } - if command.OnUpdate != "" { - sql += " on update " + command.OnUpdate - } - - return sql -} - -func (r *Sqlserver) CompileForeignKeys(schema, table string) string { - newSchema := "schema_name()" - if schema != "" { - newSchema = r.wrap.Quote(schema) - } - - return fmt.Sprintf( - `SELECT - fk.name AS name, - string_agg(lc.name, ',') WITHIN GROUP (ORDER BY fkc.constraint_column_id) AS columns, - fs.name AS foreign_schema, - ft.name AS foreign_table, - string_agg(fc.name, ',') WITHIN GROUP (ORDER BY fkc.constraint_column_id) AS foreign_columns, - fk.update_referential_action_desc AS on_update, - fk.delete_referential_action_desc AS on_delete - FROM sys.foreign_keys AS fk - JOIN sys.foreign_key_columns AS fkc ON fkc.constraint_object_id = fk.object_id - JOIN sys.tables AS lt ON lt.object_id = fk.parent_object_id - JOIN sys.schemas AS ls ON lt.schema_id = ls.schema_id - JOIN sys.columns AS lc ON fkc.parent_object_id = lc.object_id AND fkc.parent_column_id = lc.column_id - JOIN sys.tables AS ft ON ft.object_id = fk.referenced_object_id - JOIN sys.schemas AS fs ON ft.schema_id = fs.schema_id - JOIN sys.columns AS fc ON fkc.referenced_object_id = fc.object_id AND fkc.referenced_column_id = fc.column_id - WHERE lt.name = %s AND ls.name = %s - GROUP BY fk.name, fs.name, ft.name, fk.update_referential_action_desc, fk.delete_referential_action_desc`, - r.wrap.Quote(table), - newSchema, - ) -} - -func (r *Sqlserver) CompileFullText(_ schema.Blueprint, _ *schema.Command) string { - return "" -} - -func (r *Sqlserver) CompileIndex(blueprint schema.Blueprint, command *schema.Command) string { - return fmt.Sprintf("create index %s on %s (%s)", - r.wrap.Column(command.Index), - r.wrap.Table(blueprint.GetTableName()), - r.wrap.Columnize(command.Columns), - ) -} - -func (r *Sqlserver) CompileIndexes(schema, table string) string { - newSchema := "schema_name()" - if schema != "" { - newSchema = r.wrap.Quote(schema) - } - - return fmt.Sprintf( - "select idx.name as name, string_agg(col.name, ',') within group (order by idxcol.key_ordinal) as columns, "+ - "idx.type_desc as [type], idx.is_unique as [unique], idx.is_primary_key as [primary] "+ - "from sys.indexes as idx "+ - "join sys.tables as tbl on idx.object_id = tbl.object_id "+ - "join sys.schemas as scm on tbl.schema_id = scm.schema_id "+ - "join sys.index_columns as idxcol on idx.object_id = idxcol.object_id and idx.index_id = idxcol.index_id "+ - "join sys.columns as col on idxcol.object_id = col.object_id and idxcol.column_id = col.column_id "+ - "where tbl.name = %s and scm.name = %s "+ - "group by idx.name, idx.type_desc, idx.is_unique, idx.is_primary_key", - r.wrap.Quote(table), - newSchema, - ) -} - -func (r *Sqlserver) CompilePrimary(blueprint schema.Blueprint, command *schema.Command) string { - return fmt.Sprintf("alter table %s add constraint %s primary key (%s)", - r.wrap.Table(blueprint.GetTableName()), - r.wrap.Column(command.Index), - r.wrap.Columnize(command.Columns)) -} - -func (r *Sqlserver) CompileRename(blueprint schema.Blueprint, command *schema.Command) string { - return fmt.Sprintf("sp_rename %s, %s", r.wrap.Quote(r.wrap.Table(blueprint.GetTableName())), r.wrap.Table(command.To)) -} - -func (r *Sqlserver) CompileRenameIndex(_ schema.Schema, blueprint schema.Blueprint, command *schema.Command) []string { - return []string{ - fmt.Sprintf("sp_rename %s, %s, N'INDEX'", r.wrap.Quote(r.wrap.Table(blueprint.GetTableName())+"."+r.wrap.Column(command.From)), r.wrap.Column(command.To)), - } -} - -func (r *Sqlserver) CompileTables(_ string) string { - return "select t.name as name, schema_name(t.schema_id) as [schema], sum(u.total_pages) * 8 * 1024 as size " + - "from sys.tables as t " + - "join sys.partitions as p on p.object_id = t.object_id " + - "join sys.allocation_units as u on u.container_id = p.hobt_id " + - "group by t.name, t.schema_id " + - "order by t.name" -} - -func (r *Sqlserver) CompileTypes() string { - return "" -} - -func (r *Sqlserver) CompileUnique(blueprint schema.Blueprint, command *schema.Command) string { - return fmt.Sprintf("create unique index %s on %s (%s)", - r.wrap.Column(command.Index), - r.wrap.Table(blueprint.GetTableName()), - r.wrap.Columnize(command.Columns)) -} - -func (r *Sqlserver) CompileViews(_ string) string { - return "select name, schema_name(v.schema_id) as [schema], definition from sys.views as v " + - "inner join sys.sql_modules as m on v.object_id = m.object_id " + - "order by name" -} - -func (r *Sqlserver) GetAttributeCommands() []string { - return r.attributeCommands -} - -func (r *Sqlserver) ModifyDefault(_ schema.Blueprint, column schema.ColumnDefinition) string { - if !column.IsChange() && column.GetDefault() != nil { - return fmt.Sprintf(" default %s", getDefaultValue(column.GetDefault())) - } - - return "" -} - -func (r *Sqlserver) ModifyNullable(_ schema.Blueprint, column schema.ColumnDefinition) string { - if column.GetNullable() { - return " null" - } - - return " not null" -} - -func (r *Sqlserver) ModifyIncrement(blueprint schema.Blueprint, column schema.ColumnDefinition) string { - if !column.IsChange() && slices.Contains(r.serials, column.GetType()) && column.GetAutoIncrement() { - if blueprint.HasCommand("primary") { - return " identity" - } - return " identity primary key" - } - - return "" -} - -func (r *Sqlserver) TypeBigInteger(_ schema.ColumnDefinition) string { - return "bigint" -} - -func (r *Sqlserver) TypeChar(column schema.ColumnDefinition) string { - return fmt.Sprintf("nchar(%d)", column.GetLength()) -} - -func (r *Sqlserver) TypeDate(_ schema.ColumnDefinition) string { - return "date" -} - -func (r *Sqlserver) TypeDateTime(column schema.ColumnDefinition) string { - return r.TypeTimestamp(column) -} - -func (r *Sqlserver) TypeDateTimeTz(column schema.ColumnDefinition) string { - return r.TypeTimestampTz(column) -} - -func (r *Sqlserver) TypeDecimal(column schema.ColumnDefinition) string { - return fmt.Sprintf("decimal(%d, %d)", column.GetTotal(), column.GetPlaces()) -} - -func (r *Sqlserver) TypeDouble(_ schema.ColumnDefinition) string { - return "double precision" -} - -func (r *Sqlserver) TypeEnum(column schema.ColumnDefinition) string { - return fmt.Sprintf(`nvarchar(255) check ("%s" in (%s))`, column.GetName(), strings.Join(r.wrap.Quotes(cast.ToStringSlice(column.GetAllowed())), ", ")) -} - -func (r *Sqlserver) TypeFloat(column schema.ColumnDefinition) string { - precision := column.GetPrecision() - if precision > 0 { - return fmt.Sprintf("float(%d)", precision) - } - - return "float" -} - -func (r *Sqlserver) TypeInteger(_ schema.ColumnDefinition) string { - return "int" -} - -func (r *Sqlserver) TypeJson(_ schema.ColumnDefinition) string { - return "nvarchar(max)" -} - -func (r *Sqlserver) TypeJsonb(_ schema.ColumnDefinition) string { - return "nvarchar(max)" -} - -func (r *Sqlserver) TypeLongText(_ schema.ColumnDefinition) string { - return "nvarchar(max)" -} - -func (r *Sqlserver) TypeMediumInteger(_ schema.ColumnDefinition) string { - return "int" -} - -func (r *Sqlserver) TypeMediumText(_ schema.ColumnDefinition) string { - return "nvarchar(max)" -} - -func (r *Sqlserver) TypeSmallInteger(_ schema.ColumnDefinition) string { - return "smallint" -} - -func (r *Sqlserver) TypeString(column schema.ColumnDefinition) string { - length := column.GetLength() - if length > 0 { - return fmt.Sprintf("nvarchar(%d)", length) - } - - return "nvarchar(255)" -} - -func (r *Sqlserver) TypeText(_ schema.ColumnDefinition) string { - return "nvarchar(max)" -} - -func (r *Sqlserver) TypeTime(column schema.ColumnDefinition) string { - if column.GetPrecision() > 0 { - return fmt.Sprintf("time(%d)", column.GetPrecision()) - } else { - return "time" - } -} - -func (r *Sqlserver) TypeTimeTz(column schema.ColumnDefinition) string { - return r.TypeTime(column) -} - -func (r *Sqlserver) TypeTimestamp(column schema.ColumnDefinition) string { - if column.GetUseCurrent() { - column.Default(Expression("CURRENT_TIMESTAMP")) - } - - if column.GetPrecision() > 0 { - return fmt.Sprintf("datetime2(%d)", column.GetPrecision()) - } else { - return "datetime" - } -} - -func (r *Sqlserver) TypeTimestampTz(column schema.ColumnDefinition) string { - if column.GetUseCurrent() { - column.Default(Expression("CURRENT_TIMESTAMP")) - } - - if column.GetPrecision() > 0 { - return fmt.Sprintf("datetimeoffset(%d)", column.GetPrecision()) - } else { - return "datetimeoffset" - } -} - -func (r *Sqlserver) TypeTinyInteger(_ schema.ColumnDefinition) string { - return "tinyint" -} - -func (r *Sqlserver) TypeTinyText(_ schema.ColumnDefinition) string { - return "nvarchar(255)" -} - -func (r *Sqlserver) getColumns(blueprint schema.Blueprint) []string { - var columns []string - for _, column := range blueprint.GetAddedColumns() { - columns = append(columns, r.getColumn(blueprint, column)) - } - - return columns -} - -func (r *Sqlserver) getColumn(blueprint schema.Blueprint, column schema.ColumnDefinition) string { - sql := fmt.Sprintf("%s %s", r.wrap.Column(column.GetName()), getType(r, column)) - - for _, modifier := range r.modifiers { - sql += modifier(blueprint, column) - } - - return sql -} diff --git a/database/schema/grammars/sqlserver_test.go b/database/schema/grammars/sqlserver_test.go deleted file mode 100644 index 132229545..000000000 --- a/database/schema/grammars/sqlserver_test.go +++ /dev/null @@ -1,398 +0,0 @@ -package grammars - -import ( - "testing" - - "github.com/stretchr/testify/suite" - - contractsschema "github.com/goravel/framework/contracts/database/schema" - mocksschema "github.com/goravel/framework/mocks/database/schema" -) - -type SqlserverSuite struct { - suite.Suite - grammar *Sqlserver -} - -func TestSqlserverSuite(t *testing.T) { - suite.Run(t, &SqlserverSuite{}) -} - -func (s *SqlserverSuite) SetupTest() { - s.grammar = NewSqlserver("goravel_") -} - -func (s *SqlserverSuite) TestCompileAdd() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockColumn := mocksschema.NewColumnDefinition(s.T()) - - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - mockColumn.EXPECT().GetName().Return("name").Once() - mockColumn.EXPECT().GetType().Return("string").Twice() - mockColumn.EXPECT().GetDefault().Return("goravel").Twice() - mockColumn.EXPECT().GetNullable().Return(false).Once() - mockColumn.EXPECT().GetLength().Return(1).Once() - mockColumn.EXPECT().IsChange().Return(false).Twice() - - sql := s.grammar.CompileAdd(mockBlueprint, &contractsschema.Command{ - Column: mockColumn, - }) - - s.Equal(`alter table "goravel_users" add "name" nvarchar(1) default 'goravel' not null`, sql) -} - -func (s *SqlserverSuite) TestCompileChange() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockColumn := mocksschema.NewColumnDefinition(s.T()) - - mockBlueprint.EXPECT().GetTableName().Return("users").Twice() - mockColumn.EXPECT().GetName().Return("name").Twice() - mockColumn.EXPECT().GetType().Return("string").Once() - mockColumn.EXPECT().GetNullable().Return(false).Once() - mockColumn.EXPECT().GetLength().Return(1).Once() - mockColumn.EXPECT().IsChange().Return(true).Times(3) - - sql := s.grammar.CompileChange(mockBlueprint, &contractsschema.Command{ - Column: mockColumn, - }) - - s.Equal([]string{ - `DECLARE @sql NVARCHAR(MAX) = '';SELECT @sql += 'ALTER TABLE "goravel_users" DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' FROM sys.columns WHERE [object_id] = OBJECT_ID('"goravel_users"') AND [name] in ('name') AND [default_object_id] <> 0;EXEC(@sql);`, - `alter table "goravel_users" alter column "name" nvarchar(1) not null`, - }, sql) -} - -func (s *SqlserverSuite) TestCompileCreate() { - mockColumn1 := mocksschema.NewColumnDefinition(s.T()) - mockColumn2 := mocksschema.NewColumnDefinition(s.T()) - mockBlueprint := mocksschema.NewBlueprint(s.T()) - - // postgres.go::CompileCreate - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - // utils.go::getColumns - mockBlueprint.EXPECT().GetAddedColumns().Return([]contractsschema.ColumnDefinition{ - mockColumn1, mockColumn2, - }).Once() - // utils.go::getColumns - mockColumn1.EXPECT().GetName().Return("id").Once() - // utils.go::getType - mockColumn1.EXPECT().GetType().Return("integer").Once() - // postgres.go::TypeInteger - mockColumn1.EXPECT().GetAutoIncrement().Return(true).Once() - // postgres.go::ModifyDefault - mockColumn1.EXPECT().GetDefault().Return(nil).Once() - // postgres.go::ModifyIncrement - mockBlueprint.EXPECT().HasCommand("primary").Return(false).Once() - mockColumn1.EXPECT().GetType().Return("integer").Once() - // postgres.go::ModifyNullable - mockColumn1.EXPECT().GetNullable().Return(false).Once() - mockColumn1.EXPECT().IsChange().Return(false).Twice() - - // utils.go::getColumns - mockColumn2.EXPECT().GetName().Return("name").Once() - // utils.go::getType - mockColumn2.EXPECT().GetType().Return("string").Once() - // postgres.go::TypeString - mockColumn2.EXPECT().GetLength().Return(100).Once() - // postgres.go::ModifyDefault - mockColumn2.EXPECT().GetDefault().Return(nil).Once() - // postgres.go::ModifyIncrement - mockColumn2.EXPECT().GetType().Return("string").Once() - // postgres.go::ModifyNullable - mockColumn2.EXPECT().GetNullable().Return(true).Once() - mockColumn2.EXPECT().IsChange().Return(false).Twice() - - s.Equal(`create table "goravel_users" ("id" int identity primary key not null, "name" nvarchar(100) null)`, - s.grammar.CompileCreate(mockBlueprint)) -} - -func (s *SqlserverSuite) TestCompileDefault() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockColumnDefinition := mocksschema.NewColumnDefinition(s.T()) - - mockColumnDefinition.EXPECT().IsChange().Return(true).Once() - mockColumnDefinition.EXPECT().GetDefault().Return("default").Twice() - mockColumnDefinition.EXPECT().GetName().Return("id").Once() - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - - sql := s.grammar.CompileDefault(mockBlueprint, &contractsschema.Command{ - Column: mockColumnDefinition, - }) - - s.Equal(`alter table "goravel_users" add default 'default' for "id"`, sql) -} - -func (s *SqlserverSuite) TestCompileDropColumn() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockBlueprint.EXPECT().GetTableName().Return("users").Twice() - - s.Equal([]string{`DECLARE @sql NVARCHAR(MAX) = '';SELECT @sql += 'ALTER TABLE "goravel_users" DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' FROM sys.columns WHERE [object_id] = OBJECT_ID('"goravel_users"') AND [name] in ('id','name') AND [default_object_id] <> 0;EXEC(@sql); alter table "goravel_users" drop column "id", "name"`}, s.grammar.CompileDropColumn(mockBlueprint, &contractsschema.Command{ - Columns: []string{"id", "name"}, - })) -} - -func (s *SqlserverSuite) TestCompileDropIfExists() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - - s.Equal(`if object_id('"goravel_users"', 'U') is not null drop table "goravel_users"`, s.grammar.CompileDropIfExists(mockBlueprint)) -} - -func (s *SqlserverSuite) TestCompileForeign() { - var mockBlueprint *mocksschema.Blueprint - - beforeEach := func() { - mockBlueprint = mocksschema.NewBlueprint(s.T()) - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - } - - tests := []struct { - name string - command *contractsschema.Command - expectSql string - }{ - { - name: "with on delete and on update", - command: &contractsschema.Command{ - Index: "fk_users_role_id", - Columns: []string{"role_id", "user_id"}, - On: "roles", - References: []string{"id", "user_id"}, - OnDelete: "cascade", - OnUpdate: "restrict", - }, - expectSql: `alter table "goravel_users" add constraint "fk_users_role_id" foreign key ("role_id", "user_id") references "goravel_roles" ("id", "user_id") on delete cascade on update restrict`, - }, - { - name: "without on delete and on update", - command: &contractsschema.Command{ - Index: "fk_users_role_id", - Columns: []string{"role_id", "user_id"}, - On: "roles", - References: []string{"id", "user_id"}, - }, - expectSql: `alter table "goravel_users" add constraint "fk_users_role_id" foreign key ("role_id", "user_id") references "goravel_roles" ("id", "user_id")`, - }, - } - - for _, test := range tests { - s.Run(test.name, func() { - beforeEach() - - sql := s.grammar.CompileForeign(mockBlueprint, test.command) - s.Equal(test.expectSql, sql) - }) - } -} - -func (s *SqlserverSuite) TestCompileIndex() { - var mockBlueprint *mocksschema.Blueprint - - beforeEach := func() { - mockBlueprint = mocksschema.NewBlueprint(s.T()) - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - } - - tests := []struct { - name string - command *contractsschema.Command - expectSql string - }{ - { - name: "with Algorithm", - command: &contractsschema.Command{ - Index: "fk_users_role_id", - Columns: []string{"role_id", "user_id"}, - Algorithm: "btree", - }, - expectSql: `create index "fk_users_role_id" on "goravel_users" ("role_id", "user_id")`, - }, - { - name: "without Algorithm", - command: &contractsschema.Command{ - Index: "fk_users_role_id", - Columns: []string{"role_id", "user_id"}, - }, - expectSql: `create index "fk_users_role_id" on "goravel_users" ("role_id", "user_id")`, - }, - } - - for _, test := range tests { - s.Run(test.name, func() { - beforeEach() - - sql := s.grammar.CompileIndex(mockBlueprint, test.command) - s.Equal(test.expectSql, sql) - }) - } -} - -func (s *SqlserverSuite) TestCompilePrimary() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - - s.Equal(`alter table "goravel_users" add constraint "role" primary key ("role_id", "user_id")`, s.grammar.CompilePrimary(mockBlueprint, &contractsschema.Command{ - Columns: []string{"role_id", "user_id"}, - Index: "role", - })) -} - -func (s *SqlserverSuite) TestGetColumns() { - mockColumn1 := mocksschema.NewColumnDefinition(s.T()) - mockColumn2 := mocksschema.NewColumnDefinition(s.T()) - mockBlueprint := mocksschema.NewBlueprint(s.T()) - - mockBlueprint.EXPECT().GetAddedColumns().Return([]contractsschema.ColumnDefinition{ - mockColumn1, mockColumn2, - }).Once() - mockBlueprint.EXPECT().HasCommand("primary").Return(false).Once() - - mockColumn1.EXPECT().GetName().Return("id").Once() - mockColumn1.EXPECT().GetType().Return("integer").Twice() - mockColumn1.EXPECT().GetDefault().Return(nil).Once() - mockColumn1.EXPECT().GetNullable().Return(false).Once() - mockColumn1.EXPECT().GetAutoIncrement().Return(true).Once() - mockColumn1.EXPECT().IsChange().Return(false).Twice() - - mockColumn2.EXPECT().GetName().Return("name").Once() - mockColumn2.EXPECT().GetType().Return("string").Twice() - mockColumn2.EXPECT().GetDefault().Return("goravel").Twice() - mockColumn2.EXPECT().GetNullable().Return(true).Once() - mockColumn2.EXPECT().GetLength().Return(10).Once() - mockColumn2.EXPECT().IsChange().Return(false).Twice() - - s.Equal([]string{`"id" int identity primary key not null`, `"name" nvarchar(10) default 'goravel' null`}, s.grammar.getColumns(mockBlueprint)) -} - -func (s *SqlserverSuite) TestModifyDefault() { - var ( - mockBlueprint *mocksschema.Blueprint - mockColumn *mocksschema.ColumnDefinition - ) - - tests := []struct { - name string - setup func() - expectSql string - }{ - { - name: "without change and default is nil", - setup: func() { - mockColumn.EXPECT().IsChange().Return(false).Once() - mockColumn.EXPECT().GetDefault().Return(nil).Once() - }, - }, - { - name: "without change and default is not nil", - setup: func() { - mockColumn.EXPECT().IsChange().Return(false).Once() - mockColumn.EXPECT().GetDefault().Return("goravel").Twice() - }, - expectSql: " default 'goravel'", - }, - } - - for _, test := range tests { - s.Run(test.name, func() { - mockBlueprint = mocksschema.NewBlueprint(s.T()) - mockColumn = mocksschema.NewColumnDefinition(s.T()) - - test.setup() - - sql := s.grammar.ModifyDefault(mockBlueprint, mockColumn) - - s.Equal(test.expectSql, sql) - }) - } -} - -func (s *SqlserverSuite) TestModifyNullable() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - mockColumn := mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetNullable().Return(true).Once() - - s.Equal(" null", s.grammar.ModifyNullable(mockBlueprint, mockColumn)) - - mockColumn.EXPECT().GetNullable().Return(false).Once() - - s.Equal(" not null", s.grammar.ModifyNullable(mockBlueprint, mockColumn)) -} - -func (s *SqlserverSuite) TestModifyIncrement() { - mockBlueprint := mocksschema.NewBlueprint(s.T()) - - mockColumn := mocksschema.NewColumnDefinition(s.T()) - mockBlueprint.EXPECT().HasCommand("primary").Return(false).Once() - mockColumn.EXPECT().GetType().Return("bigInteger").Once() - mockColumn.EXPECT().GetAutoIncrement().Return(true).Once() - mockColumn.EXPECT().IsChange().Return(false).Once() - - s.Equal(" identity primary key", s.grammar.ModifyIncrement(mockBlueprint, mockColumn)) -} - -func (s *SqlserverSuite) TestTypeDecimal() { - mockColumn := mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetTotal().Return(4).Once() - mockColumn.EXPECT().GetPlaces().Return(2).Once() - - s.Equal("decimal(4, 2)", s.grammar.TypeDecimal(mockColumn)) -} - -func (s *SqlserverSuite) TestTypeEnum() { - mockColumn := mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetName().Return("a").Once() - mockColumn.EXPECT().GetAllowed().Return([]any{"a", "b"}).Once() - - s.Equal(`nvarchar(255) check ("a" in (N'a', N'b'))`, s.grammar.TypeEnum(mockColumn)) -} - -func (s *SqlserverSuite) TestTypeFloat() { - mockColumn := mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetPrecision().Return(0).Once() - - s.Equal("float", s.grammar.TypeFloat(mockColumn)) - - mockColumn.EXPECT().GetPrecision().Return(2).Once() - - s.Equal("float(2)", s.grammar.TypeFloat(mockColumn)) -} - -func (s *SqlserverSuite) TestTypeString() { - mockColumn1 := mocksschema.NewColumnDefinition(s.T()) - mockColumn1.EXPECT().GetLength().Return(100).Once() - - s.Equal("nvarchar(100)", s.grammar.TypeString(mockColumn1)) - - mockColumn2 := mocksschema.NewColumnDefinition(s.T()) - mockColumn2.EXPECT().GetLength().Return(0).Once() - - s.Equal("nvarchar(255)", s.grammar.TypeString(mockColumn2)) -} - -func (s *SqlserverSuite) TestTypeTimestamp() { - mockColumn := mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetUseCurrent().Return(true).Once() - mockColumn.EXPECT().Default(Expression("CURRENT_TIMESTAMP")).Return(mockColumn).Once() - mockColumn.EXPECT().GetPrecision().Return(3).Twice() - s.Equal("datetime2(3)", s.grammar.TypeTimestamp(mockColumn)) - - mockColumn = mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetUseCurrent().Return(true).Once() - mockColumn.EXPECT().Default(Expression("CURRENT_TIMESTAMP")).Return(mockColumn).Once() - mockColumn.EXPECT().GetPrecision().Return(0).Once() - s.Equal("datetime", s.grammar.TypeTimestamp(mockColumn)) -} - -func (s *SqlserverSuite) TestTypeTimestampTz() { - mockColumn := mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetUseCurrent().Return(true).Once() - mockColumn.EXPECT().Default(Expression("CURRENT_TIMESTAMP")).Return(mockColumn).Once() - mockColumn.EXPECT().GetPrecision().Return(3).Twice() - s.Equal("datetimeoffset(3)", s.grammar.TypeTimestampTz(mockColumn)) - - mockColumn = mocksschema.NewColumnDefinition(s.T()) - mockColumn.EXPECT().GetUseCurrent().Return(true).Once() - mockColumn.EXPECT().Default(Expression("CURRENT_TIMESTAMP")).Return(mockColumn).Once() - mockColumn.EXPECT().GetPrecision().Return(0).Once() - s.Equal("datetimeoffset", s.grammar.TypeTimestampTz(mockColumn)) -} diff --git a/database/schema/grammars/utils.go b/database/schema/grammars/utils.go deleted file mode 100644 index eb74a2252..000000000 --- a/database/schema/grammars/utils.go +++ /dev/null @@ -1,63 +0,0 @@ -package grammars - -import ( - "fmt" - "reflect" - "unicode" - - "github.com/spf13/cast" - - "github.com/goravel/framework/contracts/database/schema" -) - -type Expression string - -func getCommandByName(commands []*schema.Command, name string) *schema.Command { - commands = getCommandsByName(commands, name) - if len(commands) == 0 { - return nil - } - - return commands[0] -} - -func getCommandsByName(commands []*schema.Command, name string) []*schema.Command { - var filteredCommands []*schema.Command - for _, command := range commands { - if command.Name == name { - filteredCommands = append(filteredCommands, command) - } - } - - return filteredCommands -} - -func getDefaultValue(def any) string { - switch value := def.(type) { - case bool: - return "'" + cast.ToString(cast.ToInt(value)) + "'" - case Expression: - return string(value) - default: - return "'" + cast.ToString(def) + "'" - } -} - -func getType(grammar schema.Grammar, column schema.ColumnDefinition) string { - t := []rune(column.GetType()) - if len(t) == 0 { - return "" - } - - t[0] = unicode.ToUpper(t[0]) - methodName := fmt.Sprintf("Type%s", string(t)) - methodValue := reflect.ValueOf(grammar).MethodByName(methodName) - if methodValue.IsValid() { - args := []reflect.Value{reflect.ValueOf(column)} - callResult := methodValue.Call(args) - - return callResult[0].String() - } - - return "" -} diff --git a/database/schema/grammars/utils_test.go b/database/schema/grammars/utils_test.go deleted file mode 100644 index a963718ef..000000000 --- a/database/schema/grammars/utils_test.go +++ /dev/null @@ -1,63 +0,0 @@ -package grammars - -import ( - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/goravel/framework/contracts/database/schema" - mocksschema "github.com/goravel/framework/mocks/database/schema" -) - -func TestGetCommandByName(t *testing.T) { - commands := []*schema.Command{ - {Name: "create"}, - {Name: "update"}, - {Name: "delete"}, - } - - // Test case: Command exists - result := getCommandByName(commands, "update") - assert.NotNil(t, result) - assert.Equal(t, "update", result.Name) - - // Test case: Command does not exist - result = getCommandByName(commands, "drop") - assert.Nil(t, result) -} - -func TestGetDefaultValue(t *testing.T) { - def := true - assert.Equal(t, "'1'", getDefaultValue(def)) - - def = false - assert.Equal(t, "'0'", getDefaultValue(def)) - - defInt := 123 - assert.Equal(t, "'123'", getDefaultValue(defInt)) - - defString := "abc" - assert.Equal(t, "'abc'", getDefaultValue(defString)) - - defExpression := Expression("abc") - assert.Equal(t, "abc", getDefaultValue(defExpression)) -} - -func TestGetType(t *testing.T) { - // valid type - mockColumn := mocksschema.NewColumnDefinition(t) - mockColumn.EXPECT().GetType().Return("string").Once() - - mockGrammar := mocksschema.NewGrammar(t) - mockGrammar.EXPECT().TypeString(mockColumn).Return("varchar").Once() - - assert.Equal(t, "varchar", getType(mockGrammar, mockColumn)) - - // invalid type - mockColumn1 := mocksschema.NewColumnDefinition(t) - mockColumn1.EXPECT().GetType().Return("invalid").Once() - - mockGrammar1 := mocksschema.NewGrammar(t) - - assert.Empty(t, getType(mockGrammar1, mockColumn1)) -} diff --git a/database/schema/grammars/wrap.go b/database/schema/grammars/wrap.go deleted file mode 100644 index ef2e1a598..000000000 --- a/database/schema/grammars/wrap.go +++ /dev/null @@ -1,119 +0,0 @@ -package grammars - -import ( - "fmt" - "strings" - - contractsdatabase "github.com/goravel/framework/contracts/database" - "github.com/goravel/framework/support/collect" -) - -type Wrap struct { - driver contractsdatabase.Driver - tablePrefix string -} - -func NewWrap(driver contractsdatabase.Driver, tablePrefix string) *Wrap { - return &Wrap{ - driver: driver, - tablePrefix: tablePrefix, - } -} - -func (r *Wrap) Column(column string) string { - if strings.Contains(column, " as ") { - return r.aliasedValue(column) - } - - return r.Segments(strings.Split(column, ".")) -} - -func (r *Wrap) Columns(columns []string) []string { - formatedColumns := make([]string, len(columns)) - for i, column := range columns { - formatedColumns[i] = r.Column(column) - } - - return formatedColumns -} - -func (r *Wrap) Columnize(columns []string) string { - columns = r.Columns(columns) - - return strings.Join(columns, ", ") -} - -func (r *Wrap) GetPrefix() string { - return r.tablePrefix -} - -func (r *Wrap) PrefixArray(prefix string, values []string) []string { - return collect.Map(values, func(value string, _ int) string { - return prefix + " " + value - }) -} - -func (r *Wrap) Quote(value string) string { - if value == "" { - return value - } - - return fmt.Sprintf("'%s'", value) -} - -func (r *Wrap) Quotes(value []string) []string { - return collect.Map(value, func(v string, _ int) string { - if r.driver == contractsdatabase.DriverSqlserver { - return "N" + r.Quote(v) - } - return r.Quote(v) - }) -} - -func (r *Wrap) Segments(segments []string) string { - for i, segment := range segments { - if i == 0 && len(segments) > 1 { - segments[i] = r.Table(segment) - } else { - segments[i] = r.Value(segment) - } - } - - return strings.Join(segments, ".") -} - -func (r *Wrap) Table(table string) string { - if strings.Contains(table, " as ") { - return r.aliasedTable(table) - } - if strings.Contains(table, ".") { - lastDotIndex := strings.LastIndex(table, ".") - - return r.Value(table[:lastDotIndex]) + "." + r.Value(r.tablePrefix+table[lastDotIndex+1:]) - } - - return r.Value(r.tablePrefix + table) -} - -func (r *Wrap) Value(value string) string { - if value != "*" { - if r.driver == contractsdatabase.DriverMysql { - return "`" + strings.ReplaceAll(value, "`", "``") + "`" - } - return `"` + strings.ReplaceAll(value, `"`, `""`) + `"` - } - - return value -} - -func (r *Wrap) aliasedTable(table string) string { - segments := strings.Split(table, " as ") - - return r.Table(segments[0]) + " as " + r.Value(r.tablePrefix+segments[1]) -} - -func (r *Wrap) aliasedValue(value string) string { - segments := strings.Split(value, " as ") - - return r.Column(segments[0]) + " as " + r.Value(r.tablePrefix+segments[1]) -} diff --git a/database/schema/grammars/wrap_test.go b/database/schema/grammars/wrap_test.go deleted file mode 100644 index d234a745f..000000000 --- a/database/schema/grammars/wrap_test.go +++ /dev/null @@ -1,90 +0,0 @@ -package grammars - -import ( - "testing" - - "github.com/stretchr/testify/suite" - - "github.com/goravel/framework/contracts/database" -) - -type WrapTestSuite struct { - suite.Suite - wrap *Wrap -} - -func TestWrapSuite(t *testing.T) { - suite.Run(t, new(WrapTestSuite)) -} - -func (s *WrapTestSuite) SetupTest() { - s.wrap = NewWrap(database.DriverPostgres, "prefix_") -} - -func (s *WrapTestSuite) TestColumn() { - // With alias - result := s.wrap.Column("column as alias") - s.Equal(`"column" as "prefix_alias"`, result) - - // Without alias - result = s.wrap.Column("column") - s.Equal(`"column"`, result) -} - -func (s *WrapTestSuite) TestColumnize() { - result := s.wrap.Columnize([]string{"column1", "column2 as alias2"}) - s.Equal(`"column1", "column2" as "prefix_alias2"`, result) -} - -func (s *WrapTestSuite) TestQuote() { - // With non empty value - result := s.wrap.Quote("value") - s.Equal("'value'", result) - - // With empty value - result = s.wrap.Quote("") - s.Equal("", result) -} - -func (s *WrapTestSuite) TestQuotes() { - result := s.wrap.Quotes([]string{"value1", "value2"}) - s.Equal([]string{"'value1'", "'value2'"}, result) - - s.wrap.driver = database.DriverSqlserver - result = s.wrap.Quotes([]string{"value1", "value2"}) - s.Equal([]string{"N'value1'", "N'value2'"}, result) -} - -func (s *WrapTestSuite) TestSegmentsWithMultipleSegments() { - result := s.wrap.Segments([]string{"table", "column"}) - s.Equal(`"prefix_table"."column"`, result) -} - -func (s *WrapTestSuite) TestTable() { - // With alias - result := s.wrap.Table("table as alias") - s.Equal(`"prefix_table" as "prefix_alias"`, result) - - // With schema - result = s.wrap.Table("goravel.table") - s.Equal(`"goravel"."prefix_table"`, result) - - // Without alias - result = s.wrap.Table("table") - s.Equal(`"prefix_table"`, result) -} - -func (s *WrapTestSuite) TestValue() { - // With asterisk - result := s.wrap.Value("*") - s.Equal("*", result) - - // Without asterisk - result = s.wrap.Value("value") - s.Equal(`"value"`, result) - - // With mysql - s.wrap.driver = database.DriverMysql - result = s.wrap.Value("value") - s.Equal("`value`", result) -} diff --git a/database/schema/mysql_schema.go b/database/schema/mysql_schema.go deleted file mode 100644 index 0e33ccb0a..000000000 --- a/database/schema/mysql_schema.go +++ /dev/null @@ -1,107 +0,0 @@ -package schema - -import ( - "github.com/goravel/framework/contracts/database/orm" - contractsschema "github.com/goravel/framework/contracts/database/schema" - "github.com/goravel/framework/database/schema/grammars" - "github.com/goravel/framework/database/schema/processors" -) - -type MysqlSchema struct { - contractsschema.CommonSchema - - grammar *grammars.Mysql - orm orm.Orm - prefix string - processor processors.Mysql -} - -func NewMysqlSchema(grammar *grammars.Mysql, orm orm.Orm, prefix string) *MysqlSchema { - return &MysqlSchema{ - CommonSchema: NewCommonSchema(grammar, orm), - grammar: grammar, - orm: orm, - prefix: prefix, - processor: processors.NewMysql(), - } -} - -func (r *MysqlSchema) DropAllTables() error { - tables, err := r.GetTables() - if err != nil { - return err - } - - if len(tables) == 0 { - return nil - } - - return r.orm.Transaction(func(tx orm.Query) error { - if _, err = tx.Exec(r.grammar.CompileDisableForeignKeyConstraints()); err != nil { - return err - } - - var dropTables []string - for _, table := range tables { - dropTables = append(dropTables, table.Name) - } - if _, err = tx.Exec(r.grammar.CompileDropAllTables(dropTables)); err != nil { - return err - } - - if _, err = tx.Exec(r.grammar.CompileEnableForeignKeyConstraints()); err != nil { - return err - } - - return err - }) -} - -func (r *MysqlSchema) DropAllTypes() error { - return nil -} - -func (r *MysqlSchema) DropAllViews() error { - views, err := r.GetViews() - if err != nil { - return err - } - if len(views) == 0 { - return nil - } - - var dropViews []string - for _, view := range views { - dropViews = append(dropViews, view.Name) - } - - _, err = r.orm.Query().Exec(r.grammar.CompileDropAllViews(dropViews)) - - return err -} - -func (r *MysqlSchema) GetColumns(table string) ([]contractsschema.Column, error) { - table = r.prefix + table - - var dbColumns []contractsschema.DBColumn - if err := r.orm.Query().Raw(r.grammar.CompileColumns(r.orm.DatabaseName(), table)).Scan(&dbColumns); err != nil { - return nil, err - } - - return r.processor.ProcessColumns(dbColumns), nil -} - -func (r *MysqlSchema) GetIndexes(table string) ([]contractsschema.Index, error) { - table = r.prefix + table - - var dbIndexes []contractsschema.DBIndex - if err := r.orm.Query().Raw(r.grammar.CompileIndexes(r.orm.DatabaseName(), table)).Scan(&dbIndexes); err != nil { - return nil, err - } - - return r.processor.ProcessIndexes(dbIndexes), nil -} - -func (r *MysqlSchema) GetTypes() ([]contractsschema.Type, error) { - return nil, nil -} diff --git a/database/schema/processors/mysql.go b/database/schema/processors/mysql.go deleted file mode 100644 index ed35d873d..000000000 --- a/database/schema/processors/mysql.go +++ /dev/null @@ -1,74 +0,0 @@ -package processors - -import ( - "strings" - - "github.com/goravel/framework/contracts/database/schema" -) - -type Mysql struct { -} - -func NewMysql() Mysql { - return Mysql{} -} - -func (r Mysql) ProcessColumns(dbColumns []schema.DBColumn) []schema.Column { - var columns []schema.Column - for _, dbColumn := range dbColumns { - var nullable bool - if dbColumn.Nullable == "YES" { - nullable = true - } - var autoIncrement bool - if dbColumn.Extra == "auto_increment" { - autoIncrement = true - } - - columns = append(columns, schema.Column{ - Autoincrement: autoIncrement, - Collation: dbColumn.Collation, - Comment: dbColumn.Comment, - Default: dbColumn.Default, - Name: dbColumn.Name, - Nullable: nullable, - Type: dbColumn.Type, - TypeName: dbColumn.TypeName, - }) - } - - return columns -} - -func (r Mysql) ProcessForeignKeys(dbForeignKeys []schema.DBForeignKey) []schema.ForeignKey { - var foreignKeys []schema.ForeignKey - for _, dbForeignKey := range dbForeignKeys { - foreignKeys = append(foreignKeys, schema.ForeignKey{ - Name: dbForeignKey.Name, - Columns: strings.Split(dbForeignKey.Columns, ","), - ForeignSchema: dbForeignKey.ForeignSchema, - ForeignTable: dbForeignKey.ForeignTable, - ForeignColumns: strings.Split(dbForeignKey.ForeignColumns, ","), - OnUpdate: strings.ToLower(dbForeignKey.OnUpdate), - OnDelete: strings.ToLower(dbForeignKey.OnDelete), - }) - } - - return foreignKeys -} - -func (r Mysql) ProcessIndexes(dbIndexes []schema.DBIndex) []schema.Index { - var indexes []schema.Index - for _, dbIndex := range dbIndexes { - name := strings.ToLower(dbIndex.Name) - indexes = append(indexes, schema.Index{ - Columns: strings.Split(dbIndex.Columns, ","), - Name: name, - Type: strings.ToLower(dbIndex.Type), - Primary: name == "primary", - Unique: dbIndex.Unique, - }) - } - - return indexes -} diff --git a/database/schema/processors/mysql_test.go b/database/schema/processors/mysql_test.go deleted file mode 100644 index ac4b97411..000000000 --- a/database/schema/processors/mysql_test.go +++ /dev/null @@ -1,100 +0,0 @@ -package processors - -import ( - "testing" - - "github.com/stretchr/testify/suite" - - "github.com/goravel/framework/contracts/database/schema" -) - -type MysqlTestSuite struct { - suite.Suite - mysql Mysql -} - -func TestMysqlTestSuite(t *testing.T) { - suite.Run(t, new(MysqlTestSuite)) -} - -func (s *MysqlTestSuite) SetupTest() { - s.mysql = NewMysql() -} - -func (s *MysqlTestSuite) TestProcessColumns() { - tests := []struct { - name string - dbColumns []schema.DBColumn - expected []schema.Column - }{ - { - name: "ValidInput", - dbColumns: []schema.DBColumn{ - {Name: "id", Type: "int", TypeName: "INT", Nullable: "NO", Extra: "auto_increment", Collation: "utf8_general_ci", Comment: "primary key", Default: "0"}, - {Name: "name", Type: "varchar", TypeName: "VARCHAR", Nullable: "YES", Extra: "", Collation: "utf8_general_ci", Comment: "user name", Default: ""}, - }, - expected: []schema.Column{ - {Autoincrement: true, Collation: "utf8_general_ci", Comment: "primary key", Default: "0", Name: "id", Nullable: false, Type: "int", TypeName: "INT"}, - {Autoincrement: false, Collation: "utf8_general_ci", Comment: "user name", Default: "", Name: "name", Nullable: true, Type: "varchar", TypeName: "VARCHAR"}, - }, - }, - { - name: "EmptyInput", - dbColumns: []schema.DBColumn{}, - }, - { - name: "NullableColumn", - dbColumns: []schema.DBColumn{ - {Name: "description", Type: "text", TypeName: "TEXT", Nullable: "YES", Extra: "", Collation: "utf8_general_ci", Comment: "description", Default: ""}, - }, - expected: []schema.Column{ - {Autoincrement: false, Collation: "utf8_general_ci", Comment: "description", Default: "", Name: "description", Nullable: true, Type: "text", TypeName: "TEXT"}, - }, - }, - { - name: "NonNullableColumn", - dbColumns: []schema.DBColumn{ - {Name: "created_at", Type: "timestamp", TypeName: "TIMESTAMP", Nullable: "NO", Extra: "", Collation: "", Comment: "creation time", Default: "CURRENT_TIMESTAMP"}, - }, - expected: []schema.Column{ - {Autoincrement: false, Collation: "", Comment: "creation time", Default: "CURRENT_TIMESTAMP", Name: "created_at", Nullable: false, Type: "timestamp", TypeName: "TIMESTAMP"}, - }, - }, - } - - for _, tt := range tests { - s.Run(tt.name, func() { - result := s.mysql.ProcessColumns(tt.dbColumns) - s.Equal(tt.expected, result) - }) - } -} - -func (s *MysqlTestSuite) TestProcessForeignKeys() { - tests := []struct { - name string - dbForeignKeys []schema.DBForeignKey - expected []schema.ForeignKey - }{ - { - name: "ValidInput", - dbForeignKeys: []schema.DBForeignKey{ - {Name: "fk_user_id", Columns: "user_id", ForeignSchema: "public", ForeignTable: "users", ForeignColumns: "id", OnUpdate: "CASCADE", OnDelete: "SET NULL"}, - }, - expected: []schema.ForeignKey{ - {Name: "fk_user_id", Columns: []string{"user_id"}, ForeignSchema: "public", ForeignTable: "users", ForeignColumns: []string{"id"}, OnUpdate: "cascade", OnDelete: "set null"}, - }, - }, - { - name: "EmptyInput", - dbForeignKeys: []schema.DBForeignKey{}, - }, - } - - for _, tt := range tests { - s.Run(tt.name, func() { - result := s.mysql.ProcessForeignKeys(tt.dbForeignKeys) - s.Equal(tt.expected, result) - }) - } -} diff --git a/database/schema/processors/sqlite.go b/database/schema/processors/sqlite.go deleted file mode 100644 index 0579d5815..000000000 --- a/database/schema/processors/sqlite.go +++ /dev/null @@ -1,92 +0,0 @@ -package processors - -import ( - "strings" - - "github.com/spf13/cast" - - "github.com/goravel/framework/contracts/database/schema" - "github.com/goravel/framework/support/collect" -) - -type Sqlite struct { -} - -func NewSqlite() Sqlite { - return Sqlite{} -} - -func (r Sqlite) ProcessColumns(dbColumns []schema.DBColumn) []schema.Column { - var primaryKeyNum int - collect.Map(dbColumns, func(dbColumn schema.DBColumn, _ int) bool { - if dbColumn.Primary { - primaryKeyNum++ - } - - return true - }) - - var columns []schema.Column - for _, dbColumn := range dbColumns { - ttype := strings.ToLower(dbColumn.Type) - typeNameParts := strings.SplitN(ttype, "(", 2) - typeName := "" - if len(typeNameParts) > 0 { - typeName = typeNameParts[0] - } - - columns = append(columns, schema.Column{ - Autoincrement: primaryKeyNum == 1 && dbColumn.Primary && ttype == "integer", - Default: dbColumn.Default, - Name: dbColumn.Name, - Nullable: cast.ToBool(dbColumn.Nullable), - Type: ttype, - TypeName: typeName, - }) - } - - return columns -} - -func (r Sqlite) ProcessForeignKeys(dbForeignKeys []schema.DBForeignKey) []schema.ForeignKey { - var foreignKeys []schema.ForeignKey - for _, dbForeignKey := range dbForeignKeys { - foreignKeys = append(foreignKeys, schema.ForeignKey{ - Name: dbForeignKey.Name, - Columns: strings.Split(dbForeignKey.Columns, ","), - ForeignTable: dbForeignKey.ForeignTable, - ForeignColumns: strings.Split(dbForeignKey.ForeignColumns, ","), - OnUpdate: strings.ToLower(dbForeignKey.OnUpdate), - OnDelete: strings.ToLower(dbForeignKey.OnDelete), - }) - } - - return foreignKeys -} - -func (r Sqlite) ProcessIndexes(dbIndexes []schema.DBIndex) []schema.Index { - var ( - indexes []schema.Index - primaryCount int - ) - for _, dbIndex := range dbIndexes { - if dbIndex.Primary { - primaryCount++ - } - - indexes = append(indexes, schema.Index{ - Columns: strings.Split(dbIndex.Columns, ","), - Name: strings.ToLower(dbIndex.Name), - Primary: dbIndex.Primary, - Unique: dbIndex.Unique, - }) - } - - if primaryCount > 1 { - indexes = collect.Filter(indexes, func(index schema.Index, _ int) bool { - return !index.Primary - }) - } - - return indexes -} diff --git a/database/schema/processors/sqlite_test.go b/database/schema/processors/sqlite_test.go deleted file mode 100644 index 8c0b76f75..000000000 --- a/database/schema/processors/sqlite_test.go +++ /dev/null @@ -1,144 +0,0 @@ -package processors - -import ( - "testing" - - "github.com/stretchr/testify/suite" - - "github.com/goravel/framework/contracts/database/schema" -) - -type SqliteTestSuite struct { - suite.Suite - sqlite Sqlite -} - -func TestSqliteTestSuite(t *testing.T) { - suite.Run(t, new(SqliteTestSuite)) -} - -func (s *SqliteTestSuite) SetupTest() { - s.sqlite = NewSqlite() -} - -func (s *SqliteTestSuite) TestProcessColumns() { - tests := []struct { - name string - dbColumns []schema.DBColumn - expected []schema.Column - }{ - { - name: "ValidInput", - dbColumns: []schema.DBColumn{ - {Name: "id", Type: "integer", Nullable: "false", Primary: true, Default: "1"}, - {Name: "name", Type: "varchar", Nullable: "true", Default: "default_name"}, - }, - expected: []schema.Column{ - {Autoincrement: true, Default: "1", Name: "id", Nullable: false, Type: "integer", TypeName: "integer"}, - {Autoincrement: false, Default: "default_name", Name: "name", Nullable: true, Type: "varchar", TypeName: "varchar"}, - }, - }, - { - name: "EmptyInput", - dbColumns: []schema.DBColumn{}, - }, - { - name: "NullableColumn", - dbColumns: []schema.DBColumn{ - {Name: "description", Type: "text", Nullable: "true", Default: "default_description"}, - }, - expected: []schema.Column{ - {Autoincrement: false, Default: "default_description", Name: "description", Nullable: true, Type: "text", TypeName: "text"}, - }, - }, - { - name: "NonNullableColumn", - dbColumns: []schema.DBColumn{ - {Name: "created_at", Type: "timestamp", Nullable: "false", Default: "CURRENT_TIMESTAMP"}, - }, - expected: []schema.Column{ - {Autoincrement: false, Default: "CURRENT_TIMESTAMP", Name: "created_at", Nullable: false, Type: "timestamp", TypeName: "timestamp"}, - }, - }, - } - - sqlite := NewSqlite() - for _, tt := range tests { - s.Run(tt.name, func() { - result := sqlite.ProcessColumns(tt.dbColumns) - s.Equal(tt.expected, result) - }) - } -} - -func (s *SqliteTestSuite) TestProcessForeignKeys() { - tests := []struct { - name string - dbForeignKeys []schema.DBForeignKey - expected []schema.ForeignKey - }{ - { - name: "ValidInput", - dbForeignKeys: []schema.DBForeignKey{ - {Name: "fk_user_id", Columns: "user_id", ForeignTable: "users", ForeignColumns: "id", OnUpdate: "CASCADE", OnDelete: "SET NULL"}, - }, - expected: []schema.ForeignKey{ - {Name: "fk_user_id", Columns: []string{"user_id"}, ForeignTable: "users", ForeignColumns: []string{"id"}, OnUpdate: "cascade", OnDelete: "set null"}, - }, - }, - { - name: "EmptyInput", - dbForeignKeys: []schema.DBForeignKey{}, - }, - } - - sqlite := NewSqlite() - for _, tt := range tests { - s.Run(tt.name, func() { - result := sqlite.ProcessForeignKeys(tt.dbForeignKeys) - s.Equal(tt.expected, result) - }) - } -} - -func (s *SqliteTestSuite) TestProcessIndexes() { - // Test with valid indexes - input := []schema.DBIndex{ - {Name: "INDEX_A", Type: "BTREE", Columns: "a,b"}, - {Name: "INDEX_B", Type: "HASH", Columns: "c,d"}, - {Name: "INDEX_C", Type: "HASH", Columns: "e,f", Primary: true}, - } - expected := []schema.Index{ - {Name: "index_a", Columns: []string{"a", "b"}}, - {Name: "index_b", Columns: []string{"c", "d"}}, - {Name: "index_c", Columns: []string{"e", "f"}, Primary: true}, - } - - sqlite := NewSqlite() - result := sqlite.ProcessIndexes(input) - - s.Equal(expected, result) - - // Test with valid indexes with multiple primary keys - input = []schema.DBIndex{ - {Name: "INDEX_A", Type: "BTREE", Columns: "a,b"}, - {Name: "INDEX_B", Type: "HASH", Columns: "c,d"}, - {Name: "INDEX_C", Type: "HASH", Columns: "e,f", Primary: true}, - {Name: "INDEX_D", Type: "HASH", Columns: "g,h", Primary: true}, - } - expected = []schema.Index{ - {Name: "index_a", Columns: []string{"a", "b"}}, - {Name: "index_b", Columns: []string{"c", "d"}}, - } - - result = sqlite.ProcessIndexes(input) - - s.Equal(expected, result) - - // Test with empty input - input = []schema.DBIndex{} - - result = sqlite.ProcessIndexes(input) - - s.Nil(result) -} diff --git a/database/schema/processors/sqlserver.go b/database/schema/processors/sqlserver.go deleted file mode 100644 index 55106f51b..000000000 --- a/database/schema/processors/sqlserver.go +++ /dev/null @@ -1,76 +0,0 @@ -package processors - -import ( - "fmt" - "strings" - - "github.com/spf13/cast" - - "github.com/goravel/framework/contracts/database/schema" -) - -type Sqlserver struct { -} - -func NewSqlserver() Sqlserver { - return Sqlserver{} -} - -func (r Sqlserver) ProcessColumns(dbColumns []schema.DBColumn) []schema.Column { - var columns []schema.Column - for _, dbColumn := range dbColumns { - columns = append(columns, schema.Column{ - Autoincrement: dbColumn.Autoincrement, - Collation: dbColumn.Collation, - Comment: dbColumn.Comment, - Default: dbColumn.Default, - Name: dbColumn.Name, - Nullable: cast.ToBool(dbColumn.Nullable), - Type: getType(dbColumn), - TypeName: dbColumn.TypeName, - }) - } - - return columns -} - -func (r Sqlserver) ProcessForeignKeys(dbForeignKeys []schema.DBForeignKey) []schema.ForeignKey { - var foreignKeys []schema.ForeignKey - for _, dbForeignKey := range dbForeignKeys { - foreignKeys = append(foreignKeys, schema.ForeignKey{ - Name: dbForeignKey.Name, - Columns: strings.Split(dbForeignKey.Columns, ","), - ForeignSchema: dbForeignKey.ForeignSchema, - ForeignTable: dbForeignKey.ForeignTable, - ForeignColumns: strings.Split(dbForeignKey.ForeignColumns, ","), - OnUpdate: strings.ToLower(strings.ReplaceAll(dbForeignKey.OnUpdate, "_", " ")), - OnDelete: strings.ToLower(strings.ReplaceAll(dbForeignKey.OnDelete, "_", " ")), - }) - } - - return foreignKeys -} - -func (r Sqlserver) ProcessIndexes(dbIndexes []schema.DBIndex) []schema.Index { - return processIndexes(dbIndexes) -} - -func getType(dbColumn schema.DBColumn) string { - var typeName string - switch dbColumn.TypeName { - case "binary", "varbinary", "char", "varchar", "nchar", "nvarchar": - if dbColumn.Length == -1 { - typeName = dbColumn.TypeName + "(max)" - } else { - typeName = fmt.Sprintf("%s(%d)", dbColumn.TypeName, dbColumn.Length) - } - case "decimal", "numeric": - typeName = fmt.Sprintf("%s(%d,%d)", dbColumn.TypeName, dbColumn.Precision, dbColumn.Places) - case "float", "datetime2", "datetimeoffset", "time": - typeName = fmt.Sprintf("%s(%d)", dbColumn.TypeName, dbColumn.Precision) - default: - typeName = dbColumn.TypeName - } - - return typeName -} diff --git a/database/schema/processors/sqlserver_test.go b/database/schema/processors/sqlserver_test.go deleted file mode 100644 index 42c33794e..000000000 --- a/database/schema/processors/sqlserver_test.go +++ /dev/null @@ -1,148 +0,0 @@ -package processors - -import ( - "testing" - - "github.com/stretchr/testify/suite" - - "github.com/goravel/framework/contracts/database/schema" -) - -type SqlserverTestSuite struct { - suite.Suite - sqlserver Sqlserver -} - -func TestSqlserverTestSuite(t *testing.T) { - suite.Run(t, new(SqlserverTestSuite)) -} - -func (s *SqlserverTestSuite) SetupTest() { - s.sqlserver = NewSqlserver() -} - -func (s *SqlserverTestSuite) TestProcessColumns() { - tests := []struct { - name string - dbColumns []schema.DBColumn - expected []schema.Column - }{ - { - name: "ValidInput", - dbColumns: []schema.DBColumn{ - {Name: "id", TypeName: "int", Nullable: "false", Autoincrement: true, Collation: "utf8_general_ci", Comment: "primary key", Default: "1"}, - {Name: "name", TypeName: "varchar", Nullable: "true", Collation: "utf8_general_ci", Comment: "user name", Default: "default_name", Length: 10}, - }, - expected: []schema.Column{ - {Autoincrement: true, Collation: "utf8_general_ci", Comment: "primary key", Default: "1", Name: "id", Nullable: false, Type: "int", TypeName: "int"}, - {Autoincrement: false, Collation: "utf8_general_ci", Comment: "user name", Default: "default_name", Name: "name", Nullable: true, Type: "varchar(10)", TypeName: "varchar"}, - }, - }, - { - name: "EmptyInput", - dbColumns: []schema.DBColumn{}, - }, - { - name: "NullableColumn", - dbColumns: []schema.DBColumn{ - {Name: "description", TypeName: "text", Nullable: "true", Collation: "utf8_general_ci", Comment: "description", Default: "default_description"}, - }, - expected: []schema.Column{ - {Autoincrement: false, Collation: "utf8_general_ci", Comment: "description", Default: "default_description", Name: "description", Nullable: true, Type: "text", TypeName: "text"}, - }, - }, - { - name: "NonNullableColumn", - dbColumns: []schema.DBColumn{ - {Name: "created_at", TypeName: "timestamp", Nullable: "false", Collation: "", Comment: "creation time", Default: "CURRENT_TIMESTAMP"}, - }, - expected: []schema.Column{ - {Autoincrement: false, Collation: "", Comment: "creation time", Default: "CURRENT_TIMESTAMP", Name: "created_at", Nullable: false, Type: "timestamp", TypeName: "timestamp"}, - }, - }, - } - - sqlserver := NewSqlserver() - for _, tt := range tests { - s.Run(tt.name, func() { - result := sqlserver.ProcessColumns(tt.dbColumns) - s.Equal(tt.expected, result) - }) - } -} - -func (s *SqlserverTestSuite) TestProcessForeignKeys() { - tests := []struct { - name string - dbForeignKeys []schema.DBForeignKey - expected []schema.ForeignKey - }{ - { - name: "ValidInput", - dbForeignKeys: []schema.DBForeignKey{ - {Name: "fk_user_id", Columns: "user_id", ForeignSchema: "dbo", ForeignTable: "users", ForeignColumns: "id", OnUpdate: "CASCADE", OnDelete: "SET_NULL"}, - }, - expected: []schema.ForeignKey{ - {Name: "fk_user_id", Columns: []string{"user_id"}, ForeignSchema: "dbo", ForeignTable: "users", ForeignColumns: []string{"id"}, OnUpdate: "cascade", OnDelete: "set null"}, - }, - }, - { - name: "EmptyInput", - dbForeignKeys: []schema.DBForeignKey{}, - }, - } - - sqlserver := NewSqlserver() - for _, tt := range tests { - s.Run(tt.name, func() { - result := sqlserver.ProcessForeignKeys(tt.dbForeignKeys) - s.Equal(tt.expected, result) - }) - } -} - -func (s *SqlserverTestSuite) TestGetType() { - tests := []struct { - name string - dbColumn schema.DBColumn - expected string - }{ - { - name: "BinaryWithMaxLength", - dbColumn: schema.DBColumn{TypeName: "binary", Length: -1}, - expected: "binary(max)", - }, - { - name: "VarbinaryWithSpecificLength", - dbColumn: schema.DBColumn{TypeName: "varbinary", Length: 255}, - expected: "varbinary(255)", - }, - { - name: "CharWithSpecificLength", - dbColumn: schema.DBColumn{TypeName: "char", Length: 10}, - expected: "char(10)", - }, - { - name: "DecimalWithPrecisionAndScale", - dbColumn: schema.DBColumn{TypeName: "decimal", Precision: 10, Places: 2}, - expected: "decimal(10,2)", - }, - { - name: "FloatWithPrecision", - dbColumn: schema.DBColumn{TypeName: "float", Precision: 5}, - expected: "float(5)", - }, - { - name: "DefaultTypeName", - dbColumn: schema.DBColumn{TypeName: "int"}, - expected: "int", - }, - } - - for _, tt := range tests { - s.Run(tt.name, func() { - result := getType(tt.dbColumn) - s.Equal(tt.expected, result) - }) - } -} diff --git a/database/schema/processors/utils.go b/database/schema/processors/utils.go deleted file mode 100644 index 9ce16f12f..000000000 --- a/database/schema/processors/utils.go +++ /dev/null @@ -1,22 +0,0 @@ -package processors - -import ( - "strings" - - "github.com/goravel/framework/contracts/database/schema" -) - -func processIndexes(dbIndexes []schema.DBIndex) []schema.Index { - var indexes []schema.Index - for _, dbIndex := range dbIndexes { - indexes = append(indexes, schema.Index{ - Columns: strings.Split(dbIndex.Columns, ","), - Name: strings.ToLower(dbIndex.Name), - Type: strings.ToLower(dbIndex.Type), - Primary: dbIndex.Primary, - Unique: dbIndex.Unique, - }) - } - - return indexes -} diff --git a/database/schema/processors/utils_test.go b/database/schema/processors/utils_test.go deleted file mode 100644 index 6cf6d313e..000000000 --- a/database/schema/processors/utils_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package processors - -import ( - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/goravel/framework/contracts/database/schema" -) - -func TestProcessIndexes(t *testing.T) { - // Test with valid indexes - input := []schema.DBIndex{ - {Name: "INDEX_A", Type: "BTREE", Columns: "a,b"}, - {Name: "INDEX_B", Type: "HASH", Columns: "c,d"}, - } - expected := []schema.Index{ - {Name: "index_a", Type: "btree", Columns: []string{"a", "b"}}, - {Name: "index_b", Type: "hash", Columns: []string{"c", "d"}}, - } - - result := processIndexes(input) - - assert.Equal(t, expected, result) - - // Test with empty input - input = []schema.DBIndex{} - - result = processIndexes(input) - - assert.Nil(t, result) -} diff --git a/database/schema/sqlite_schema.go b/database/schema/sqlite_schema.go deleted file mode 100644 index 93c38146e..000000000 --- a/database/schema/sqlite_schema.go +++ /dev/null @@ -1,99 +0,0 @@ -package schema - -import ( - "github.com/goravel/framework/contracts/database/orm" - "github.com/goravel/framework/contracts/database/schema" - "github.com/goravel/framework/database/schema/grammars" - "github.com/goravel/framework/database/schema/processors" -) - -type SqliteSchema struct { - schema.CommonSchema - - grammar *grammars.Sqlite - orm orm.Orm - prefix string - processor processors.Sqlite -} - -func NewSqliteSchema(grammar *grammars.Sqlite, orm orm.Orm, prefix string) *SqliteSchema { - return &SqliteSchema{ - CommonSchema: NewCommonSchema(grammar, orm), - grammar: grammar, - orm: orm, - prefix: prefix, - processor: processors.NewSqlite(), - } -} - -func (r *SqliteSchema) DropAllTables() error { - if _, err := r.orm.Query().Exec(r.grammar.CompileEnableWriteableSchema()); err != nil { - return err - } - if _, err := r.orm.Query().Exec(r.grammar.CompileDropAllTables(nil)); err != nil { - return err - } - if _, err := r.orm.Query().Exec(r.grammar.CompileDisableWriteableSchema()); err != nil { - return err - } - if _, err := r.orm.Query().Exec(r.grammar.CompileRebuild()); err != nil { - return err - } - - return nil -} - -func (r *SqliteSchema) DropAllTypes() error { - return nil -} - -func (r *SqliteSchema) DropAllViews() error { - if err := r.orm.Transaction(func(tx orm.Query) error { - if _, err := tx.Exec(r.grammar.CompileEnableWriteableSchema()); err != nil { - return err - } - if _, err := tx.Exec(r.grammar.CompileDropAllViews(nil)); err != nil { - return err - } - if _, err := tx.Exec(r.grammar.CompileDisableWriteableSchema()); err != nil { - return err - } - - return nil - }); err != nil { - return err - } - - // cannot VACUUM from within a transaction - if _, err := r.orm.Query().Exec(r.grammar.CompileRebuild()); err != nil { - return err - } - - return nil -} - -func (r *SqliteSchema) GetColumns(table string) ([]schema.Column, error) { - table = r.prefix + table - - var dbColumns []schema.DBColumn - if err := r.orm.Query().Raw(r.grammar.CompileColumns("", table)).Scan(&dbColumns); err != nil { - return nil, err - } - - return r.processor.ProcessColumns(dbColumns), nil -} - -func (r *SqliteSchema) GetIndexes(table string) ([]schema.Index, error) { - table = r.prefix + table - - var dbIndexes []schema.DBIndex - if err := r.orm.Query().Raw(r.grammar.CompileIndexes("", table)).Scan(&dbIndexes); err != nil { - return nil, err - } - - return r.processor.ProcessIndexes(dbIndexes), nil -} - -func (r *SqliteSchema) GetTypes() ([]schema.Type, error) { - return nil, nil -} diff --git a/database/schema/sqlserver_schema.go b/database/schema/sqlserver_schema.go deleted file mode 100644 index 3220707cb..000000000 --- a/database/schema/sqlserver_schema.go +++ /dev/null @@ -1,85 +0,0 @@ -package schema - -import ( - "github.com/goravel/framework/contracts/database/orm" - contractsschema "github.com/goravel/framework/contracts/database/schema" - "github.com/goravel/framework/database/schema/grammars" - "github.com/goravel/framework/database/schema/processors" -) - -type SqlserverSchema struct { - contractsschema.CommonSchema - - grammar *grammars.Sqlserver - orm orm.Orm - prefix string - processor processors.Sqlserver -} - -func NewSqlserverSchema(grammar *grammars.Sqlserver, orm orm.Orm, prefix string) *SqlserverSchema { - return &SqlserverSchema{ - CommonSchema: NewCommonSchema(grammar, orm), - grammar: grammar, - orm: orm, - prefix: prefix, - processor: processors.NewSqlserver(), - } -} - -func (r *SqlserverSchema) DropAllTables() error { - if _, err := r.orm.Query().Exec(r.grammar.CompileDropAllForeignKeys()); err != nil { - return err - } - - if _, err := r.orm.Query().Exec(r.grammar.CompileDropAllTables(nil)); err != nil { - return err - } - - return nil -} - -func (r *SqlserverSchema) DropAllTypes() error { - return nil -} - -func (r *SqlserverSchema) DropAllViews() error { - _, err := r.orm.Query().Exec(r.grammar.CompileDropAllViews(nil)) - - return err -} - -func (r *SqlserverSchema) GetColumns(table string) ([]contractsschema.Column, error) { - schema, table, err := parseSchemaAndTable(table, "") - if err != nil { - return nil, err - } - - table = r.prefix + table - - var dbColumns []contractsschema.DBColumn - if err := r.orm.Query().Raw(r.grammar.CompileColumns(schema, table)).Scan(&dbColumns); err != nil { - return nil, err - } - - return r.processor.ProcessColumns(dbColumns), nil -} - -func (r *SqlserverSchema) GetIndexes(table string) ([]contractsschema.Index, error) { - schema, table, err := parseSchemaAndTable(table, "") - if err != nil { - return nil, err - } - - table = r.prefix + table - - var dbIndexes []contractsschema.DBIndex - if err := r.orm.Query().Raw(r.grammar.CompileIndexes(schema, table)).Scan(&dbIndexes); err != nil { - return nil, err - } - - return r.processor.ProcessIndexes(dbIndexes), nil -} - -func (r *SqlserverSchema) GetTypes() ([]contractsschema.Type, error) { - return nil, nil -} diff --git a/go.mod b/go.mod index ca095f027..48e2b270c 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,6 @@ require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/dromara/carbon/v2 v2.5.2 github.com/gabriel-vasile/mimetype v1.4.8 - github.com/glebarez/sqlite v1.11.0 github.com/go-viper/mapstructure/v2 v2.2.1 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/golang/protobuf v1.5.4 @@ -34,8 +33,6 @@ require ( golang.org/x/crypto v0.32.0 golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 google.golang.org/grpc v1.69.4 - gorm.io/driver/mysql v1.5.7 - gorm.io/driver/sqlserver v1.5.4 gorm.io/gorm v1.25.12 ) @@ -49,7 +46,6 @@ require ( cloud.google.com/go/compute/metadata v0.6.0 // indirect cloud.google.com/go/iam v1.3.0 // indirect cloud.google.com/go/pubsub v1.45.3 // indirect - filippo.io/edwards25519 v1.1.0 // indirect github.com/RichardKnop/logging v0.0.0-20190827224416-1a693bdd4fae // indirect github.com/atotto/clipboard v0.1.4 // indirect github.com/aws/aws-sdk-go v1.55.5 // indirect @@ -68,13 +64,9 @@ require ( github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/fsnotify/fsnotify v1.8.0 // indirect - github.com/glebarez/go-sqlite v1.22.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-redsync/redsync/v4 v4.13.0 // indirect - github.com/go-sql-driver/mysql v1.8.1 // indirect - github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect - github.com/golang-sql/sqlexp v0.1.0 // indirect github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/gomodule/redigo v2.0.0+incompatible // indirect @@ -99,19 +91,16 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-localereader v0.0.1 // indirect github.com/mattn/go-runewidth v0.0.16 - github.com/microsoft/go-mssqldb v1.8.0 // indirect github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/montanaflynn/stats v0.7.1 // indirect github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect github.com/muesli/cancelreader v0.2.2 // indirect github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect - github.com/ncruces/go-strftime v0.1.9 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/rabbitmq/amqp091-go v1.10.0 // indirect - github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sagikazarmark/locafero v0.6.0 // indirect @@ -146,13 +135,9 @@ require ( google.golang.org/api v0.214.0 // indirect google.golang.org/genproto v0.0.0-20241230172942-26aa7a208def // indirect google.golang.org/genproto/googleapis/api v0.0.0-20241230172942-26aa7a208def // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 // indirect - google.golang.org/protobuf v1.36.2 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect + google.golang.org/protobuf v1.36.3 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - modernc.org/libc v1.61.7 // indirect - modernc.org/mathutil v1.7.1 // indirect - modernc.org/memory v1.8.1 // indirect - modernc.org/sqlite v1.34.4 // indirect ) diff --git a/go.sum b/go.sum index c6ecd1a5e..5d8bd6323 100644 --- a/go.sum +++ b/go.sum @@ -59,29 +59,6 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= -filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= -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/azcore v1.9.1/go.mod h1:RKUqNu35KJYcVG/fqTRqmuXJZYNhYkBrnC/hX7yGbTA= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 h1:E+OJmp2tPvt1W+amx48v1eqbjDYsgN+RzP4q16yV5eM= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1/go.mod h1:a6xsAQUZg+VsS3TJ05SRp524Hs4pZ/AeFSr5ENf0Yjo= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.1/go.mod h1:uE9zaUfEQT/nbQjVi2IblCG9iaLtZsuYZ8ne+PuQ02M= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1/go.mod h1:h8hyGFDsU5HMivxiS2iYFZsgDbU9OnnJ163x5UGVKYo= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.6.0 h1:U2rTu3Ef+7w9FHKIAXM6ZyqF3UOWJZ12zIm8zECAFfg= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.6.0/go.mod h1:9kIvujWAA58nmPmWB1m23fyWic1kYZMxD9CxaWn4Qpg= -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/internal v1.5.1/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.8.0 h1:jBQA3cKT4L2rWMpgE7Yt3Hwh2aUj8KXjIGLxjHeYNNo= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.8.0/go.mod h1:4OG6tQ9EOP/MT0NMjDlRzWoVFxfu9rN9B2X+tlSVktg= -github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.1 h1:MyVTgWR8qd/Jw1Le0NZebGBUCLbtak3bJ3z1OlqZBpw= -github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.1/go.mod h1:GpPjLhVR9dnUoJMyHWSPy71xY9/lcmpzIPZXmF0FCVY= -github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.0.0 h1:D3occbWoio4EBLkbkevetNMAVX197GkzbUMtqjGWn80= -github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.0.0/go.mod h1:bTSOgj05NGRuHHhQwAdPnYr9TOdNmKlZTgGLL6nyAdI= -github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= -github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= -github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 h1:XHOnouVk1mxXfQidrMEnLlPk9UMeRtyBTnEFtxkV0kU= -github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ= @@ -161,8 +138,6 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= -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/dromara/carbon/v2 v2.5.2 h1:GquNyA9Imda+LwS9FIzHhKg+foU2QPstH+S3idBRjKg= github.com/dromara/carbon/v2 v2.5.2/go.mod h1:zyPlND2o27sKKkRmdgLbk/qYxkmmH6Z4eE8OoM0w3DM= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= @@ -185,10 +160,6 @@ github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/ github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= -github.com/glebarez/go-sqlite v1.22.0 h1:uAcMJhaA6r3LHMTFgP0SifzgXg46yJkgxqyuyec+ruQ= -github.com/glebarez/go-sqlite v1.22.0/go.mod h1:PlBIdHe0+aUEFn+r2/uthrWq4FxbzugL0L8Li6yQJbc= -github.com/glebarez/sqlite v1.11.0 h1:wSG0irqzP6VurnMEpFGer5Li19RpIRi2qvQz++w0GMw= -github.com/glebarez/sqlite v1.11.0/go.mod h1:h8/o8j5wiAsqSPoWELDUdJXhjAhsVliSn7bWZjOhrgQ= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -209,9 +180,6 @@ github.com/go-redsync/redsync/v4 v4.8.1/go.mod h1:LmUAsQuQxhzZAoGY7JS6+dNhNmZyon github.com/go-redsync/redsync/v4 v4.13.0 h1:49X6GJfnbLGaIpBBREM/zA4uIMDXKAh1NDkvQ1EkZKA= github.com/go-redsync/redsync/v4 v4.13.0/go.mod h1:HMW4Q224GZQz6x1Xc7040Yfgacukdzu7ifTDAKiyErQ= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= -github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= -github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= -github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= @@ -240,14 +208,8 @@ github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWe github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ= github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0= github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= -github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= -github.com/golang-jwt/jwt/v5 v5.2.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-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/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -315,15 +277,11 @@ github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd h1:gbpYu9NMq8jhDVbvlGkMFWCjLFlqqEZjEmObmhUy6Vo= -github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/s2a-go v0.1.8 h1:zZDs9gcbt9ZPLV0ndSyQk6Kacx2g/X+SKYovpnz3SMM= github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.5.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/googleapis/enterprise-certificate-proxy v0.3.4 h1:XYIDZApgAnrN1c855gTgghdIA6Stxb52D5RnLI1SLyw= @@ -344,15 +302,11 @@ github.com/gookit/validate v1.5.4 h1:nwBo6vULnVUeNFCOde6RKFRbOCKJXVMnWR0ghedacLg github.com/gookit/validate v1.5.4/go.mod h1:p9sRPfpvYB4vXICBpEPzv8FoAky+XhUOhWQghgmmat4= github.com/goravel/file-rotatelogs/v2 v2.4.2 h1:g68AzbePXcm0V2CpUMc9j4qVzcDn7+7aoWSjZ51C0m4= github.com/goravel/file-rotatelogs/v2 v2.4.2/go.mod h1:23VuSW8cBS4ax5cmbV+5AaiLpq25b8UJ96IhbAkdo8I= -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/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-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 v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= @@ -361,12 +315,6 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -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= @@ -400,8 +348,6 @@ 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/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8= github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is= github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4= @@ -419,16 +365,11 @@ github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+Ei github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/microsoft/go-mssqldb v1.7.2/go.mod h1:kOvZKUdrhhFQmxLZqbwUV0rHkNkZpthMITIb2Ko1IoA= -github.com/microsoft/go-mssqldb v1.8.0 h1:7cyZ/AT7ycDsEoWPIXibd+aVKFtteUNhDGf3aobP+tw= -github.com/microsoft/go-mssqldb v1.8.0/go.mod h1:6znkekS3T2vp0waiMhen4GPU1BiAsrP+iXHcE7a7rFo= github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4= github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE= 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/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= -github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= @@ -437,8 +378,6 @@ github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELU github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a h1:2MaM6YC3mGu54x+RKAA6JiFFHlHDY1UbkxqppT7wYOg= github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a/go.mod h1:hxSnBBYLK21Vtq/PHd0S2FYCxBXzBua8ov5s1RobyRQ= -github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= -github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -454,9 +393,6 @@ github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYr github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= -github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= -github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= -github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -482,8 +418,6 @@ github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw= github.com/redis/rueidis v1.0.19 h1:s65oWtotzlIFN8eMPhyYwxlwLR1lUdhza2KtWprKYSo= github.com/redis/rueidis v1.0.19/go.mod h1:8B+r5wdnjwK3lTFml5VtxjzGOQAC+5UmujoD12pDrEo= -github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= -github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnHyvtYjDeq0zlVHn9K/ZXoy17ylucdo= github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= @@ -616,13 +550,6 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= -golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= -golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= -golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= -golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -662,8 +589,6 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= -golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -702,14 +627,6 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= 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.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= -golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -784,7 +701,6 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/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-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -794,12 +710,6 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -807,13 +717,6 @@ golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9sn golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 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.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= -golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= -golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= -golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= -golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg= golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -826,12 +729,7 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= 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.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -894,8 +792,6 @@ golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE= -golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 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= @@ -968,8 +864,8 @@ google.golang.org/genproto v0.0.0-20241230172942-26aa7a208def h1:uz2w9bZTljGBXc3 google.golang.org/genproto v0.0.0-20241230172942-26aa7a208def/go.mod h1:zNtPaqLK0Wbf5PaSZDYDR+1t5rQoBAIMh06tpzkjvY8= google.golang.org/genproto/googleapis/api v0.0.0-20241230172942-26aa7a208def h1:0Km0hi+g2KXbXL0+riZzSCKz23f4MmwicuEb00JeonI= google.golang.org/genproto/googleapis/api v0.0.0-20241230172942-26aa7a208def/go.mod h1:u2DoMSpCXjrzqLdobRccQMc9wrnMAJ1DLng0a2yqM2Q= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 h1:3UsHvIr4Wc2aW4brOaSCmcxh9ksica6fHEr8P1XhkYw= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422/go.mod h1:3ENsm/5D1mzDyhpzeRi1NR784I0BcofWBoSc5QqqMK4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f h1:OxYkA3wjPsZyBylwymxSHa7ViiW1Sml4ToBrncvFehI= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f/go.mod h1:+2Yz8+CLJbIfL9z73EW45avw8Lmge3xVElCP9zEKi50= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -1000,8 +896,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= 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.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU= -google.golang.org/protobuf v1.36.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.36.3 h1:82DV7MYdb8anAVi3qge1wSnMDrnKK7ebr+I0hHRN1BU= +google.golang.org/protobuf v1.36.3/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -1023,12 +919,6 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/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.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo= -gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM= -gorm.io/driver/sqlserver v1.5.4 h1:xA+Y1KDNspv79q43bPyjDMUgHoYHLhXYmdFcYPobg8g= -gorm.io/driver/sqlserver v1.5.4/go.mod h1:+frZ/qYmuna11zHPlh5oc2O6ZA/lS88Keb0XSH1Zh/g= -gorm.io/gorm v1.25.7-0.20240204074919-46816ad31dde/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= -gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= @@ -1038,30 +928,6 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -modernc.org/cc/v4 v4.24.4 h1:TFkx1s6dCkQpd6dKurBNmpo+G8Zl4Sq/ztJ+2+DEsh0= -modernc.org/cc/v4 v4.24.4/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0= -modernc.org/ccgo/v4 v4.23.10 h1:DnDZT/H6TtoJvQmVf7d8W+lVqEZpIJY/+0ENFh1LIHE= -modernc.org/ccgo/v4 v4.23.10/go.mod h1:vdN4h2WR5aEoNondUx26K7G8X+nuBscYnAEWSRmN2/0= -modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE= -modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ= -modernc.org/gc/v2 v2.6.1 h1:+Qf6xdG8l7B27TQ8D8lw/iFMUj1RXRBOuMUWziJOsk8= -modernc.org/gc/v2 v2.6.1/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito= -modernc.org/libc v1.61.7 h1:exz8rasFniviSgh3dH7QBnQHqYh9lolA5hVYfsiwkfo= -modernc.org/libc v1.61.7/go.mod h1:xspSrXRNVSfWfcfqgvZDVe/Hw5kv4FVC6IRfoms5v/0= -modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU= -modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg= -modernc.org/memory v1.8.1 h1:HS1HRg1jEohnuONobEq2WrLEhLyw8+J42yLFTnllm2A= -modernc.org/memory v1.8.1/go.mod h1:ZbjSvMO5NQ1A2i3bWeDiVMxIorXwdClKE/0SZ+BMotU= -modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8= -modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns= -modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w= -modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE= -modernc.org/sqlite v1.34.4 h1:sjdARozcL5KJBvYQvLlZEmctRgW9xqIZc2ncN7PU0P8= -modernc.org/sqlite v1.34.4/go.mod h1:3QQFCG2SEMtc2nv+Wq4cQCH7Hjcg+p/RMlS1XK+zwbk= -modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0= -modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A= -modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= -modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/mocks/database/driver/Driver.go b/mocks/database/driver/Driver.go index 282837666..3c7d59f66 100644 --- a/mocks/database/driver/Driver.go +++ b/mocks/database/driver/Driver.go @@ -4,6 +4,7 @@ package driver import ( database "github.com/goravel/framework/contracts/database" + driver "github.com/goravel/framework/contracts/database/driver" gorm "gorm.io/gorm" @@ -132,7 +133,7 @@ func (_c *Driver_Docker_Call) RunAndReturn(run func() (testing.DatabaseDriver, e } // Gorm provides a mock function with no fields -func (_m *Driver) Gorm() (*gorm.DB, error) { +func (_m *Driver) Gorm() (*gorm.DB, driver.GormQuery, error) { ret := _m.Called() if len(ret) == 0 { @@ -140,8 +141,9 @@ func (_m *Driver) Gorm() (*gorm.DB, error) { } var r0 *gorm.DB - var r1 error - if rf, ok := ret.Get(0).(func() (*gorm.DB, error)); ok { + var r1 driver.GormQuery + var r2 error + if rf, ok := ret.Get(0).(func() (*gorm.DB, driver.GormQuery, error)); ok { return rf() } if rf, ok := ret.Get(0).(func() *gorm.DB); ok { @@ -152,13 +154,21 @@ func (_m *Driver) Gorm() (*gorm.DB, error) { } } - if rf, ok := ret.Get(1).(func() error); ok { + if rf, ok := ret.Get(1).(func() driver.GormQuery); ok { r1 = rf() } else { - r1 = ret.Error(1) + if ret.Get(1) != nil { + r1 = ret.Get(1).(driver.GormQuery) + } } - return r0, r1 + if rf, ok := ret.Get(2).(func() error); ok { + r2 = rf() + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 } // Driver_Gorm_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Gorm' @@ -178,12 +188,12 @@ func (_c *Driver_Gorm_Call) Run(run func()) *Driver_Gorm_Call { return _c } -func (_c *Driver_Gorm_Call) Return(_a0 *gorm.DB, _a1 error) *Driver_Gorm_Call { - _c.Call.Return(_a0, _a1) +func (_c *Driver_Gorm_Call) Return(_a0 *gorm.DB, _a1 driver.GormQuery, _a2 error) *Driver_Gorm_Call { + _c.Call.Return(_a0, _a1, _a2) return _c } -func (_c *Driver_Gorm_Call) RunAndReturn(run func() (*gorm.DB, error)) *Driver_Gorm_Call { +func (_c *Driver_Gorm_Call) RunAndReturn(run func() (*gorm.DB, driver.GormQuery, error)) *Driver_Gorm_Call { _c.Call.Return(run) return _c } diff --git a/mocks/database/driver/GormQuery.go b/mocks/database/driver/GormQuery.go new file mode 100644 index 000000000..5542dd38a --- /dev/null +++ b/mocks/database/driver/GormQuery.go @@ -0,0 +1,175 @@ +// Code generated by mockery. DO NOT EDIT. + +package driver + +import ( + clause "gorm.io/gorm/clause" + + mock "github.com/stretchr/testify/mock" +) + +// GormQuery is an autogenerated mock type for the GormQuery type +type GormQuery struct { + mock.Mock +} + +type GormQuery_Expecter struct { + mock *mock.Mock +} + +func (_m *GormQuery) EXPECT() *GormQuery_Expecter { + return &GormQuery_Expecter{mock: &_m.Mock} +} + +// LockForUpdate provides a mock function with no fields +func (_m *GormQuery) LockForUpdate() clause.Expression { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for LockForUpdate") + } + + var r0 clause.Expression + if rf, ok := ret.Get(0).(func() clause.Expression); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(clause.Expression) + } + } + + return r0 +} + +// GormQuery_LockForUpdate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LockForUpdate' +type GormQuery_LockForUpdate_Call struct { + *mock.Call +} + +// LockForUpdate is a helper method to define mock.On call +func (_e *GormQuery_Expecter) LockForUpdate() *GormQuery_LockForUpdate_Call { + return &GormQuery_LockForUpdate_Call{Call: _e.mock.On("LockForUpdate")} +} + +func (_c *GormQuery_LockForUpdate_Call) Run(run func()) *GormQuery_LockForUpdate_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *GormQuery_LockForUpdate_Call) Return(_a0 clause.Expression) *GormQuery_LockForUpdate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *GormQuery_LockForUpdate_Call) RunAndReturn(run func() clause.Expression) *GormQuery_LockForUpdate_Call { + _c.Call.Return(run) + return _c +} + +// RandomOrder provides a mock function with no fields +func (_m *GormQuery) RandomOrder() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RandomOrder") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// GormQuery_RandomOrder_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RandomOrder' +type GormQuery_RandomOrder_Call struct { + *mock.Call +} + +// RandomOrder is a helper method to define mock.On call +func (_e *GormQuery_Expecter) RandomOrder() *GormQuery_RandomOrder_Call { + return &GormQuery_RandomOrder_Call{Call: _e.mock.On("RandomOrder")} +} + +func (_c *GormQuery_RandomOrder_Call) Run(run func()) *GormQuery_RandomOrder_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *GormQuery_RandomOrder_Call) Return(_a0 string) *GormQuery_RandomOrder_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *GormQuery_RandomOrder_Call) RunAndReturn(run func() string) *GormQuery_RandomOrder_Call { + _c.Call.Return(run) + return _c +} + +// SharedLock provides a mock function with no fields +func (_m *GormQuery) SharedLock() clause.Expression { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for SharedLock") + } + + var r0 clause.Expression + if rf, ok := ret.Get(0).(func() clause.Expression); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(clause.Expression) + } + } + + return r0 +} + +// GormQuery_SharedLock_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SharedLock' +type GormQuery_SharedLock_Call struct { + *mock.Call +} + +// SharedLock is a helper method to define mock.On call +func (_e *GormQuery_Expecter) SharedLock() *GormQuery_SharedLock_Call { + return &GormQuery_SharedLock_Call{Call: _e.mock.On("SharedLock")} +} + +func (_c *GormQuery_SharedLock_Call) Run(run func()) *GormQuery_SharedLock_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *GormQuery_SharedLock_Call) Return(_a0 clause.Expression) *GormQuery_SharedLock_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *GormQuery_SharedLock_Call) RunAndReturn(run func() clause.Expression) *GormQuery_SharedLock_Call { + _c.Call.Return(run) + return _c +} + +// NewGormQuery creates a new instance of GormQuery. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewGormQuery(t interface { + mock.TestingT + Cleanup(func()) +}) *GormQuery { + mock := &GormQuery{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/database/orm/Query.go b/mocks/database/orm/Query.go index 67088369c..1360fb0a8 100644 --- a/mocks/database/orm/Query.go +++ b/mocks/database/orm/Query.go @@ -3,12 +3,10 @@ package orm import ( - database "github.com/goravel/framework/contracts/database" - mock "github.com/stretchr/testify/mock" + sql "database/sql" orm "github.com/goravel/framework/contracts/database/orm" - - sql "database/sql" + mock "github.com/stretchr/testify/mock" ) // Query is an autogenerated mock type for the Query type @@ -505,18 +503,18 @@ func (_c *Query_Distinct_Call) RunAndReturn(run func(...interface{}) orm.Query) } // Driver provides a mock function with no fields -func (_m *Query) Driver() database.Driver { +func (_m *Query) Driver() string { ret := _m.Called() if len(ret) == 0 { panic("no return value specified for Driver") } - var r0 database.Driver - if rf, ok := ret.Get(0).(func() database.Driver); ok { + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() } else { - r0 = ret.Get(0).(database.Driver) + r0 = ret.Get(0).(string) } return r0 @@ -539,12 +537,12 @@ func (_c *Query_Driver_Call) Run(run func()) *Query_Driver_Call { return _c } -func (_c *Query_Driver_Call) Return(_a0 database.Driver) *Query_Driver_Call { +func (_c *Query_Driver_Call) Return(_a0 string) *Query_Driver_Call { _c.Call.Return(_a0) return _c } -func (_c *Query_Driver_Call) RunAndReturn(run func() database.Driver) *Query_Driver_Call { +func (_c *Query_Driver_Call) RunAndReturn(run func() string) *Query_Driver_Call { _c.Call.Return(run) return _c } diff --git a/support/docker/container_test.go b/support/docker/container_test.go index 7204a5cdc..8d5d52d1b 100644 --- a/support/docker/container_test.go +++ b/support/docker/container_test.go @@ -4,10 +4,11 @@ import ( "strings" "testing" - contractstesting "github.com/goravel/framework/contracts/testing" - mockstesting "github.com/goravel/framework/mocks/testing" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" + + contractstesting "github.com/goravel/framework/contracts/testing" + mockstesting "github.com/goravel/framework/mocks/testing" ) type ContainerTestSuite struct { diff --git a/support/docker/mysql.go b/support/docker/mysql.go deleted file mode 100644 index fcec7cef8..000000000 --- a/support/docker/mysql.go +++ /dev/null @@ -1,193 +0,0 @@ -package docker - -import ( - "fmt" - "time" - - "gorm.io/driver/mysql" - gormio "gorm.io/gorm" - - "github.com/goravel/framework/contracts/testing" - "github.com/goravel/framework/errors" - "github.com/goravel/framework/support/color" -) - -type MysqlImpl struct { - containerID string - database string - host string - image *testing.Image - password string - username string - port int -} - -func NewMysqlImpl(database, username, password string) *MysqlImpl { - env := []string{ - "MYSQL_ROOT_PASSWORD=" + password, - "MYSQL_DATABASE=" + database, - } - if username != "root" { - env = append(env, "MYSQL_USER="+username) - env = append(env, "MYSQL_PASSWORD="+password) - } - - return &MysqlImpl{ - database: database, - host: "127.0.0.1", - username: username, - password: password, - image: &testing.Image{ - Repository: "mysql", - Tag: "latest", - Env: env, - ExposedPorts: []string{"3306"}, - }, - } -} - -func (r *MysqlImpl) Build() error { - command, exposedPorts := imageToCommand(r.image) - containerID, err := run(command) - if err != nil { - return fmt.Errorf("init Mysql docker error: %v", err) - } - if containerID == "" { - return errors.DockerMissingContainerId.Args("Mysql") - } - - r.containerID = containerID - r.port = getExposedPort(exposedPorts, 3306) - - return nil -} - -func (r *MysqlImpl) Config() testing.DatabaseConfig { - return testing.DatabaseConfig{ - ContainerID: r.containerID, - Host: r.host, - Port: r.port, - Database: r.database, - Username: r.username, - Password: r.password, - } -} - -func (r *MysqlImpl) Database(name string) (testing.DatabaseDriver, error) { - // We want to return the DatabaseDriver instance directly, to avoid blocking test cases in different packages, - // because the test process will be clocked when creating a new container, each package should call the Ready method - // to check if the container is ready. Returning the DatabaseDriver instance directly will allow to initialize multiple - // container simultaneously. - go func() { - instance, err := r.connect("root") - if err != nil { - color.Errorf("connect Mysql error: %v", err) - return - } - - res := instance.Exec(fmt.Sprintf(`CREATE DATABASE %s;`, name)) - if res.Error != nil { - color.Errorf("create Mysql database error: %v", res.Error) - return - } - - res = instance.Exec(fmt.Sprintf("GRANT ALL PRIVILEGES ON %s.* TO `%s`@`%%`;", name, r.username)) - if res.Error != nil { - color.Errorf("grant privileges in Mysql database error: %v", res.Error) - } - }() - - mysqlImpl := NewMysqlImpl(name, r.username, r.password) - mysqlImpl.containerID = r.containerID - mysqlImpl.port = r.port - - return mysqlImpl, nil -} - -func (r *MysqlImpl) Driver() string { - return "mysql" -} - -func (r *MysqlImpl) Fresh() error { - instance, err := r.connect() - if err != nil { - return fmt.Errorf("connect Mysql error when clearing: %v", err) - } - - res := instance.Raw("select concat('drop table ',table_name,';') from information_schema.TABLES where table_schema=?;", r.database) - if res.Error != nil { - return fmt.Errorf("get tables of Mysql error: %v", res.Error) - } - - var tables []string - res = res.Scan(&tables) - if res.Error != nil { - return fmt.Errorf("get tables of Mysql error: %v", res.Error) - } - - if res := instance.Exec("SET FOREIGN_KEY_CHECKS=0;"); res.Error != nil { - return fmt.Errorf("disable foreign key check of Mysql error: %v", res.Error) - } - - for _, table := range tables { - res = instance.Exec(table) - if res.Error != nil { - return fmt.Errorf("drop table %s of Mysql error: %v", table, res.Error) - } - } - - if res := instance.Exec("SET FOREIGN_KEY_CHECKS=1;"); res.Error != nil { - return fmt.Errorf("enable foreign key check of Mysql error: %v", res.Error) - } - - return nil -} - -func (r *MysqlImpl) Image(image testing.Image) { - r.image = &image -} - -func (r *MysqlImpl) Ready() error { - _, err := r.connect() - - return err -} - -func (r *MysqlImpl) Reuse(containerID string, port int) error { - return nil -} - -func (r *MysqlImpl) Shutdown() error { - if _, err := run(fmt.Sprintf("docker stop %s", r.containerID)); err != nil { - return fmt.Errorf("stop Mysql error: %v", err) - } - - return nil -} - -func (r *MysqlImpl) connect(username ...string) (*gormio.DB, error) { - var ( - instance *gormio.DB - err error - ) - - useUsername := r.username - if len(username) > 0 { - useUsername = username[0] - } - - // docker compose need time to start - for i := 0; i < 60; i++ { - instance, err = gormio.Open(mysql.New(mysql.Config{ - DSN: fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", useUsername, r.password, r.host, r.port, r.database), - })) - - if err == nil { - break - } - - time.Sleep(2 * time.Second) - } - - return instance, err -} diff --git a/support/docker/mysql_test.go b/support/docker/mysql_test.go deleted file mode 100644 index 09f881857..000000000 --- a/support/docker/mysql_test.go +++ /dev/null @@ -1,86 +0,0 @@ -package docker - -import ( - "fmt" - "testing" - - "github.com/stretchr/testify/suite" - - "github.com/goravel/framework/contracts/database" - contractstesting "github.com/goravel/framework/contracts/testing" - configmocks "github.com/goravel/framework/mocks/config" -) - -type MysqlTestSuite struct { - suite.Suite - mockConfig *configmocks.Config - mysql *MysqlImpl -} - -func TestMysqlTestSuite(t *testing.T) { - t.Skip("Skip test that using Docker") - - suite.Run(t, new(MysqlTestSuite)) -} - -func (s *MysqlTestSuite) SetupTest() { - s.mockConfig = &configmocks.Config{} - // s.mysql = NewMysqlImpl(testDatabase, testUsername, testPassword) -} - -func (s *MysqlTestSuite) TestBuild() { - s.Nil(s.mysql.Build()) - instance, err := s.mysql.connect() - s.Nil(err) - s.NotNil(instance) - - s.Equal("127.0.0.1", s.mysql.Config().Host) - // s.Equal(testDatabase, s.mysql.Config().Database) - // s.Equal(testUsername, s.mysql.Config().Username) - // s.Equal(testPassword, s.mysql.Config().Password) - s.True(s.mysql.Config().Port > 0) - - res := instance.Exec(` -CREATE TABLE users ( - id bigint(20) unsigned NOT NULL AUTO_INCREMENT, - name varchar(255) NOT NULL, - PRIMARY KEY (id) -) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; -`) - s.Nil(res.Error) - - res = instance.Exec(` -INSERT INTO users (name) VALUES ('goravel'); -`) - s.Nil(res.Error) - s.Equal(int64(1), res.RowsAffected) - - var count int64 - res = instance.Raw(fmt.Sprintf("SELECT count(*) FROM information_schema.tables WHERE table_schema = '%s' and table_name = 'users';", s.mysql.Config().Database)).Scan(&count) - s.Nil(res.Error) - s.Equal(int64(1), count) - - s.Nil(s.mysql.Fresh()) - - res = instance.Raw(fmt.Sprintf("SELECT count(*) FROM information_schema.tables WHERE table_schema = '%s' and table_name = 'users';", s.mysql.Config().Database)).Scan(&count) - s.Nil(res.Error) - s.Equal(int64(0), count) - - databaseDriver, err := s.mysql.Database("another") - s.NoError(err) - s.NotNil(databaseDriver) - - s.Nil(s.mysql.Shutdown()) -} - -func (s *MysqlTestSuite) TestDriver() { - s.Equal(database.DriverMysql, s.mysql.Driver()) -} - -func (s *MysqlTestSuite) TestImage() { - image := contractstesting.Image{ - Repository: "mysql", - } - s.mysql.Image(image) - s.Equal(&image, s.mysql.image) -} diff --git a/support/docker/sqlite.go b/support/docker/sqlite.go deleted file mode 100644 index c052c08ce..000000000 --- a/support/docker/sqlite.go +++ /dev/null @@ -1,85 +0,0 @@ -package docker - -import ( - "fmt" - - "github.com/glebarez/sqlite" - gormio "gorm.io/gorm" - - "github.com/goravel/framework/contracts/testing" - "github.com/goravel/framework/support/file" -) - -type SqliteImpl struct { - database string -} - -func NewSqliteImpl(database string) *SqliteImpl { - return &SqliteImpl{ - database: database, - } -} - -func (r *SqliteImpl) Build() error { - if _, err := r.connect(); err != nil { - return fmt.Errorf("connect Sqlite error: %v", err) - } - - return nil -} - -func (r *SqliteImpl) Config() testing.DatabaseConfig { - return testing.DatabaseConfig{ - Database: r.database, - } -} - -func (r *SqliteImpl) Database(name string) (testing.DatabaseDriver, error) { - sqliteImpl := NewSqliteImpl(name) - if err := sqliteImpl.Build(); err != nil { - return nil, err - } - - return sqliteImpl, nil -} - -func (r *SqliteImpl) Driver() string { - return "sqlite" -} - -func (r *SqliteImpl) Fresh() error { - if err := r.Shutdown(); err != nil { - return err - } - - if _, err := r.connect(); err != nil { - return fmt.Errorf("connect Sqlite error when freshing: %v", err) - } - - return nil -} - -func (r *SqliteImpl) Image(image testing.Image) { -} - -func (r *SqliteImpl) Ready() error { - _, err := r.connect() - - return err -} - -func (r *SqliteImpl) Reuse(containerID string, port int) error { - return nil -} - -func (r *SqliteImpl) Shutdown() error { - if err := file.Remove(r.database); err != nil { - return fmt.Errorf("stop Sqlite error: %v", err) - } - - return nil -} - -func (r *SqliteImpl) connect() (*gormio.DB, error) { - return gormio.Open(sqlite.Open(fmt.Sprintf("%s?multi_stmts=true", r.database))) -} diff --git a/support/docker/sqlite_test.go b/support/docker/sqlite_test.go deleted file mode 100644 index 34856299e..000000000 --- a/support/docker/sqlite_test.go +++ /dev/null @@ -1,76 +0,0 @@ -package docker - -import ( - "testing" - - "github.com/stretchr/testify/suite" - - "github.com/goravel/framework/contracts/database" - configmocks "github.com/goravel/framework/mocks/config" -) - -type SqliteTestSuite struct { - suite.Suite - mockConfig *configmocks.Config - sqlite *SqliteImpl -} - -func TestSqliteTestSuite(t *testing.T) { - t.Skip("Skip test that using Docker") - - suite.Run(t, new(SqliteTestSuite)) -} - -func (s *SqliteTestSuite) SetupTest() { - s.mockConfig = &configmocks.Config{} - s.sqlite = NewSqliteImpl("goravel") -} - -func (s *SqliteTestSuite) TestBuild() { - s.Nil(s.sqlite.Build()) - instance, err := s.sqlite.connect() - s.Nil(err) - s.NotNil(instance) - - // s.Equal(testDatabase, s.sqlite.Config().Database) - - res := instance.Exec(` -CREATE TABLE users ( - id integer PRIMARY KEY AUTOINCREMENT NOT NULL, - name varchar(255) NOT NULL -); -`) - s.Nil(res.Error) - - res = instance.Exec(` -INSERT INTO users (name) VALUES ('goravel'); -`) - s.Nil(res.Error) - s.Equal(int64(1), res.RowsAffected) - - var count int64 - res = instance.Raw("SELECT count(*) FROM sqlite_master WHERE type='table' and name = 'users';").Scan(&count) - s.Nil(res.Error) - s.Equal(int64(1), count) - - s.Nil(s.sqlite.Fresh()) - - instance, err = s.sqlite.connect() - s.Nil(err) - s.NotNil(instance) - - res = instance.Raw("SELECT count(*) FROM sqlite_master WHERE type='table' and name = 'users';").Scan(&count) - s.Nil(res.Error) - s.Equal(int64(0), count) - - databaseDriver, err := s.sqlite.Database("another") - s.NoError(err) - s.NotNil(databaseDriver) - s.NoError(databaseDriver.Shutdown()) - - s.Nil(s.sqlite.Shutdown()) -} - -func (s *SqliteTestSuite) TestDriver() { - s.Equal(database.DriverSqlite, s.sqlite.Driver()) -} diff --git a/support/docker/sqlserver.go b/support/docker/sqlserver.go deleted file mode 100644 index b168a3f52..000000000 --- a/support/docker/sqlserver.go +++ /dev/null @@ -1,191 +0,0 @@ -package docker - -import ( - "fmt" - "time" - - "gorm.io/driver/sqlserver" - gormio "gorm.io/gorm" - - "github.com/goravel/framework/contracts/testing" -) - -type SqlserverImpl struct { - containerID string - database string - host string - image *testing.Image - password string - username string - port int -} - -func NewSqlserverImpl(database, username, password string) *SqlserverImpl { - return &SqlserverImpl{ - database: database, - host: "127.0.0.1", - username: username, - password: password, - image: &testing.Image{ - Repository: "mcr.microsoft.com/mssql/server", - Tag: "latest", - Env: []string{ - "ACCEPT_EULA=Y", - "MSSQL_SA_PASSWORD=" + password, - }, - ExposedPorts: []string{"1433"}, - }, - } -} - -func (r *SqlserverImpl) Build() error { - command, exposedPorts := imageToCommand(r.image) - containerID, err := run(command) - if err != nil { - return fmt.Errorf("init Sqlserver docker error: %v", err) - } - if containerID == "" { - return fmt.Errorf("no container id return when creating Sqlserver docker") - } - - r.containerID = containerID - r.port = getExposedPort(exposedPorts, 1433) - - return nil -} - -func (r *SqlserverImpl) Config() testing.DatabaseConfig { - return testing.DatabaseConfig{ - ContainerID: r.containerID, - Host: r.host, - Port: r.port, - Database: r.database, - Username: r.username, - Password: r.password, - } -} - -func (r *SqlserverImpl) Database(name string) (testing.DatabaseDriver, error) { - sqlserverImpl := NewSqlserverImpl(name, r.username, r.password) - sqlserverImpl.containerID = r.containerID - sqlserverImpl.port = r.port - - return sqlserverImpl, nil -} - -func (r *SqlserverImpl) Driver() string { - return "sqlserver" -} - -func (r *SqlserverImpl) Fresh() error { - instance, err := r.connect() - if err != nil { - return fmt.Errorf("connect Sqlserver error when clearing: %v", err) - } - - res := instance.Raw("SELECT NAME FROM SYSOBJECTS WHERE TYPE='U';") - if res.Error != nil { - return fmt.Errorf("get tables of Sqlserver error: %v", res.Error) - } - - var tables []string - res = res.Scan(&tables) - if res.Error != nil { - return fmt.Errorf("get tables of Sqlserver error: %v", res.Error) - } - - for _, table := range tables { - res = instance.Exec(fmt.Sprintf("drop table %s;", table)) - if res.Error != nil { - return fmt.Errorf("drop table %s of Sqlserver error: %v", table, res.Error) - } - } - - return nil -} - -func (r *SqlserverImpl) Image(image testing.Image) { - r.image = &image -} - -func (r *SqlserverImpl) Ready() error { - _, err := r.connect() - - return err -} - -func (r *SqlserverImpl) Reuse(containerID string, port int) error { - return nil -} - -func (r *SqlserverImpl) Shutdown() error { - if _, err := run(fmt.Sprintf("docker stop %s", r.containerID)); err != nil { - return fmt.Errorf("stop Sqlserver error: %v", err) - } - - return nil -} - -func (r *SqlserverImpl) connect() (*gormio.DB, error) { - var ( - instance *gormio.DB - err error - ) - - // docker compose need time to start - for i := 0; i < 100; i++ { - instance, err = gormio.Open(sqlserver.New(sqlserver.Config{ - DSN: fmt.Sprintf("sqlserver://%s:%s@%s:%d?database=master", - "sa", r.password, r.host, r.port), - })) - - if err == nil { - // Check if database exists - var exists bool - query := fmt.Sprintf("SELECT CASE WHEN EXISTS (SELECT * FROM sys.databases WHERE name = '%s') THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT) END", r.database) - if err := instance.Raw(query).Scan(&exists).Error; err != nil { - return nil, err - } - - if !exists { - // Create User database - if err := instance.Exec(fmt.Sprintf(`CREATE DATABASE "%s";`, r.database)).Error; err != nil { - return nil, err - } - - query = fmt.Sprintf("SELECT 1 FROM sys.server_principals WHERE name = '%s' AND type = 'S'", r.username) - if err := instance.Raw(query).Scan(&exists).Error; err != nil { - return nil, err - } - - if !exists { - // Create User account - if err := instance.Exec(fmt.Sprintf("CREATE LOGIN %s WITH PASSWORD = '%s'", r.username, r.password)).Error; err != nil { - return nil, err - } - } - - // Create DB account for User - if err := instance.Exec(fmt.Sprintf("USE %s; CREATE USER %s FOR LOGIN %s", r.database, r.username, r.username)).Error; err != nil { - return nil, err - } - - // Add permission - if err := instance.Exec(fmt.Sprintf("USE %s; ALTER ROLE db_owner ADD MEMBER %s", r.database, r.username)).Error; err != nil { - return nil, err - } - } - - instance, err = gormio.Open(sqlserver.New(sqlserver.Config{ - DSN: fmt.Sprintf("sqlserver://%s:%s@%s:%d?database=%s", - r.username, r.password, r.host, r.port, r.database), - })) - - break - } - - time.Sleep(2 * time.Second) - } - - return instance, err -} diff --git a/support/docker/sqlserver_test.go b/support/docker/sqlserver_test.go deleted file mode 100644 index 9e370f165..000000000 --- a/support/docker/sqlserver_test.go +++ /dev/null @@ -1,89 +0,0 @@ -package docker - -import ( - "testing" - - "github.com/stretchr/testify/suite" - - "github.com/goravel/framework/contracts/database" - contractstesting "github.com/goravel/framework/contracts/testing" - mocksconfig "github.com/goravel/framework/mocks/config" -) - -type SqlserverTestSuite struct { - suite.Suite - mockConfig *mocksconfig.Config - sqlserver *SqlserverImpl -} - -func TestSqlserverTestSuite(t *testing.T) { - t.Skip("Skip test that using Docker") - - suite.Run(t, new(SqlserverTestSuite)) -} - -func (s *SqlserverTestSuite) SetupTest() { - s.mockConfig = &mocksconfig.Config{} - // s.sqlserver = NewSqlserverImpl(testDatabase, testUsername, testPassword) -} - -func (s *SqlserverTestSuite) TestBuild() { - s.Nil(s.sqlserver.Build()) - instance, err := s.sqlserver.connect() - s.Nil(err) - s.NotNil(instance) - - s.Equal("127.0.0.1", s.sqlserver.Config().Host) - // s.Equal(testDatabase, s.sqlserver.Config().Database) - // s.Equal(testUsername, s.sqlserver.Config().Username) - // s.Equal(testPassword, s.sqlserver.Config().Password) - s.True(s.sqlserver.Config().Port > 0) - - res := instance.Exec(` - CREATE TABLE users ( - id bigint NOT NULL IDENTITY(1,1), - name varchar(255) NOT NULL, - PRIMARY KEY (id) - ); - `) - s.Nil(res.Error) - - res = instance.Exec(` - INSERT INTO users (name) VALUES ('goravel'); - `) - s.Nil(res.Error) - s.Equal(int64(1), res.RowsAffected) - - var count int64 - res = instance.Raw(` - SELECT count(*) FROM sys.tables WHERE name = 'users'; - `).Scan(&count) - s.Nil(res.Error) - s.Equal(int64(1), count) - - s.Nil(s.sqlserver.Fresh()) - - res = instance.Raw(` - SELECT count(*) FROM sys.tables WHERE name = 'users'; - `).Scan(&count) - s.Nil(res.Error) - s.Equal(int64(0), count) - - databaseDriver, err := s.sqlserver.Database("another") - s.NoError(err) - s.NotNil(databaseDriver) - - s.Nil(s.sqlserver.Shutdown()) -} - -func (s *SqlserverTestSuite) TestDriver() { - s.Equal(database.DriverSqlserver, s.sqlserver.Driver()) -} - -func (s *SqlserverTestSuite) TestImage() { - image := contractstesting.Image{ - Repository: "sqlserver", - } - s.sqlserver.Image(image) - s.Equal(&image, s.sqlserver.image) -} diff --git a/tests/factory_test.go b/tests/factory_test.go index e1199dede..df745928d 100644 --- a/tests/factory_test.go +++ b/tests/factory_test.go @@ -21,6 +21,7 @@ func TestFactoryTestSuite(t *testing.T) { func (s *FactoryTestSuite) SetupSuite() { postgresTestQuery := postgresTestQuery("", false) + postgresTestQuery.CreateTable(TestTableUsers, TestTableAuthors) s.query = postgresTestQuery.Query() } diff --git a/tests/go.mod b/tests/go.mod index 27c5af7a6..3f00d7f26 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -6,8 +6,8 @@ toolchain go1.23.4 require ( github.com/brianvoe/gofakeit/v7 v7.1.2 - github.com/goravel/framework v1.15.2 - github.com/goravel/postgres v0.0.1 + github.com/goravel/framework v1.15.2-0.20250118134235-cdd2b8b3478c + github.com/goravel/postgres v0.0.2-0.20250118135921-e5f4971c88a4 github.com/spf13/cast v1.7.1 github.com/stretchr/testify v1.10.0 gorm.io/gorm v1.25.12 @@ -17,55 +17,31 @@ require ( atomicgo.dev/cursor v0.2.0 // indirect atomicgo.dev/keyboard v0.2.9 // indirect atomicgo.dev/schedule v0.1.0 // indirect - filippo.io/edwards25519 v1.1.0 // indirect - github.com/Azure/go-autorest v14.2.0+incompatible // indirect - github.com/Azure/go-autorest/autorest/adal v0.9.16 // indirect - github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect - github.com/Azure/go-autorest/logger v0.2.1 // indirect - github.com/Azure/go-autorest/tracing v0.6.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/containerd/console v1.0.4 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/dromara/carbon/v2 v2.5.2 // indirect - github.com/dustin/go-humanize v1.0.1 // indirect github.com/gabriel-vasile/mimetype v1.4.8 // indirect - github.com/glebarez/go-sqlite v1.22.0 // indirect - github.com/glebarez/sqlite v1.11.0 // indirect github.com/go-sql-driver/mysql v1.8.1 // indirect github.com/go-viper/mapstructure/v2 v2.2.1 // indirect - github.com/golang-jwt/jwt/v4 v4.5.1 // indirect - github.com/golang-migrate/migrate/v4 v4.18.1 // indirect - github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect - github.com/golang-sql/sqlexp v0.1.0 // indirect - github.com/google/uuid v1.6.0 // indirect github.com/gookit/color v1.5.4 // indirect - github.com/hashicorp/errwrap v1.1.0 // indirect - github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/pgx/v5 v5.7.2 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect - github.com/klauspost/cpuid/v2 v2.2.9 // indirect - github.com/lib/pq v1.10.9 // indirect github.com/lithammer/fuzzysearch v1.1.8 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect - github.com/microsoft/go-mssqldb v1.8.0 // indirect - github.com/ncruces/go-strftime v0.1.9 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/pterm/pterm v0.12.80 // indirect github.com/redis/go-redis/v9 v9.7.0 // indirect - github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/samber/lo v1.47.0 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/stretchr/objx v0.5.2 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect - go.opentelemetry.io/otel v1.33.0 // indirect - go.uber.org/atomic v1.11.0 // indirect golang.org/x/crypto v0.32.0 // indirect golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect golang.org/x/net v0.34.0 // indirect @@ -73,16 +49,12 @@ require ( golang.org/x/sys v0.29.0 // indirect golang.org/x/term v0.28.0 // indirect golang.org/x/text v0.21.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect google.golang.org/grpc v1.69.4 // indirect - google.golang.org/protobuf v1.36.2 // indirect + google.golang.org/protobuf v1.36.3 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - gorm.io/driver/mysql v1.5.7 // indirect gorm.io/driver/postgres v1.5.11 // indirect - gorm.io/driver/sqlserver v1.5.4 // indirect gorm.io/plugin/dbresolver v1.5.3 // indirect - modernc.org/libc v1.61.7 // indirect - modernc.org/mathutil v1.7.1 // indirect - modernc.org/memory v1.8.1 // indirect - modernc.org/sqlite v1.34.4 // indirect ) + +replace github.com/goravel/framework => ../ diff --git a/tests/go.sum b/tests/go.sum index 18280cd73..26a7de465 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -8,41 +8,6 @@ atomicgo.dev/schedule v0.1.0 h1:nTthAbhZS5YZmgYbb2+DH8uQIZcTlIrd4eYr3UQxEjs= atomicgo.dev/schedule v0.1.0/go.mod h1:xeUa3oAkiuHYh8bKiQBRojqAMq3PXXbJujjb0hw8pEU= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= -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/azcore v1.9.1/go.mod h1:RKUqNu35KJYcVG/fqTRqmuXJZYNhYkBrnC/hX7yGbTA= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 h1:E+OJmp2tPvt1W+amx48v1eqbjDYsgN+RzP4q16yV5eM= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1/go.mod h1:a6xsAQUZg+VsS3TJ05SRp524Hs4pZ/AeFSr5ENf0Yjo= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.1/go.mod h1:uE9zaUfEQT/nbQjVi2IblCG9iaLtZsuYZ8ne+PuQ02M= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1/go.mod h1:h8hyGFDsU5HMivxiS2iYFZsgDbU9OnnJ163x5UGVKYo= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.6.0 h1:U2rTu3Ef+7w9FHKIAXM6ZyqF3UOWJZ12zIm8zECAFfg= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.6.0/go.mod h1:9kIvujWAA58nmPmWB1m23fyWic1kYZMxD9CxaWn4Qpg= -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/internal v1.5.1/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.8.0 h1:jBQA3cKT4L2rWMpgE7Yt3Hwh2aUj8KXjIGLxjHeYNNo= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.8.0/go.mod h1:4OG6tQ9EOP/MT0NMjDlRzWoVFxfu9rN9B2X+tlSVktg= -github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.1 h1:MyVTgWR8qd/Jw1Le0NZebGBUCLbtak3bJ3z1OlqZBpw= -github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.1/go.mod h1:GpPjLhVR9dnUoJMyHWSPy71xY9/lcmpzIPZXmF0FCVY= -github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.0.0 h1:D3occbWoio4EBLkbkevetNMAVX197GkzbUMtqjGWn80= -github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.0.0/go.mod h1:bTSOgj05NGRuHHhQwAdPnYr9TOdNmKlZTgGLL6nyAdI= -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/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs= -github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= -github.com/Azure/go-autorest/autorest/adal v0.9.16 h1:P8An8Z9rH1ldbOLdFpxYorgOt2sywL9V24dAwWHPuGc= -github.com/Azure/go-autorest/autorest/adal v0.9.16/go.mod h1:tGMin8I49Yij6AQ+rvV+Xa/zwxYQB5hmsd6DkfAx2+A= -github.com/Azure/go-autorest/autorest/date v0.3.0 h1:7gUk1U5M/CQbp9WoqinNzJar+8KY+LPI6wiWrP/myHw= -github.com/Azure/go-autorest/autorest/date v0.3.0/go.mod h1:BI0uouVdmngYNUzGWeSYnokU+TrmwEsOqdt8Y6sso74= -github.com/Azure/go-autorest/autorest/mocks v0.4.1 h1:K0laFcLE6VLTOwNgSxaGbUcLPuGXlNkbVvq4cW4nIHk= -github.com/Azure/go-autorest/autorest/mocks v0.4.1/go.mod h1:LTp+uSrOhSkaKrUy935gNZuuIPPVsHlr9DSOxSayd+k= -github.com/Azure/go-autorest/logger v0.2.1 h1:IG7i4p/mDa2Ce4TRyAO8IHnVhAVF3RFU+ZtXWSmf4Tg= -github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8= -github.com/Azure/go-autorest/tracing v0.6.0 h1:TYi4+3m5t6K48TGI9AUdb+IzbnSxvnvUMfuitfgcfuo= -github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU= -github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= -github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= -github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 h1:XHOnouVk1mxXfQidrMEnLlPk9UMeRtyBTnEFtxkV0kU= -github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/MarvinJWendt/testza v0.1.0/go.mod h1:7AxNvlfeHP7Z/hDQ5JtE3OKYT3XFUeLCDE2DQninSqs= github.com/MarvinJWendt/testza v0.2.1/go.mod h1:God7bhG8n6uQxwdScay+gjm9/LnO4D3kkcZX4hv9Rp8= github.com/MarvinJWendt/testza v0.2.8/go.mod h1:nwIcjmr0Zz+Rcwfh3/4UhBp7ePKVhuBExvZqnKYWlII= @@ -52,8 +17,6 @@ github.com/MarvinJWendt/testza v0.3.0/go.mod h1:eFcL4I0idjtIx8P9C6KkAuLgATNKpX4/ github.com/MarvinJWendt/testza v0.4.2/go.mod h1:mSdhXiKH8sg/gQehJ63bINcCKp7RtYewEjXsvsVUPbE= github.com/MarvinJWendt/testza v0.5.2 h1:53KDo64C1z/h/d/stCYCPY69bt/OSwjq5KpFNwi+zB4= github.com/MarvinJWendt/testza v0.5.2/go.mod h1:xu53QFE5sCdjtMCKk8YMQ2MnymimEctc4n3EjyIYvEY= -github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= -github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk= github.com/brianvoe/gofakeit/v7 v7.1.2 h1:vSKaVScNhWVpf1rlyEKSvO8zKZfuDtGqoIHT//iNNb8= github.com/brianvoe/gofakeit/v7 v7.1.2/go.mod h1:QXuPeBw164PJCzCUZVmgpgHJ3Llj49jSLVkKPMtxtxA= @@ -72,31 +35,12 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= -github.com/dhui/dktest v0.4.3 h1:wquqUxAFdcUgabAVLvSCOKOlag5cIZuaOjYIBOWdsR0= -github.com/dhui/dktest v0.4.3/go.mod h1:zNK8IwktWzQRm6I/l2Wjp7MakiyaFWv4G1hjmodmMTs= -github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= -github.com/distribution/reference v0.6.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 v27.2.0+incompatible h1:Rk9nIVdfH3+Vz4cyI/uhbINhEZ/oLmc+CBXmH6fbNk4= -github.com/docker/docker v27.2.0+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= -github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c= -github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= -github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= -github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/dromara/carbon/v2 v2.5.2 h1:GquNyA9Imda+LwS9FIzHhKg+foU2QPstH+S3idBRjKg= github.com/dromara/carbon/v2 v2.5.2/go.mod h1:zyPlND2o27sKKkRmdgLbk/qYxkmmH6Z4eE8OoM0w3DM= -github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= -github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= -github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= -github.com/glebarez/go-sqlite v1.22.0 h1:uAcMJhaA6r3LHMTFgP0SifzgXg46yJkgxqyuyec+ruQ= -github.com/glebarez/go-sqlite v1.22.0/go.mod h1:PlBIdHe0+aUEFn+r2/uthrWq4FxbzugL0L8Li6yQJbc= -github.com/glebarez/sqlite v1.11.0 h1:wSG0irqzP6VurnMEpFGer5Li19RpIRi2qvQz++w0GMw= -github.com/glebarez/sqlite v1.11.0/go.mod h1:h8/o8j5wiAsqSPoWELDUdJXhjAhsVliSn7bWZjOhrgQ= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= @@ -106,45 +50,18 @@ github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpv github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= -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/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= -github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo= -github.com/golang-jwt/jwt/v4 v4.5.1/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.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.18.1 h1:JML/k+t4tpHCpQTCAD62Nu43NUFzHY4CV3uAuvHGC+Y= -github.com/golang-migrate/migrate/v4 v4.18.1/go.mod h1:HAX6m3sQgcdO81tdjn5exv20+3Kb13cmGli1hrD6hks= -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/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= 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/pprof v0.0.0-20240409012703-83162a5b38cd h1:gbpYu9NMq8jhDVbvlGkMFWCjLFlqqEZjEmObmhUy6Vo= -github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.5.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/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ= github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo= github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0= github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w= -github.com/goravel/framework v1.15.2 h1:wC76iwXWpYz3Oj+WQKw/kC4yGluDIeRdmPFKQW3t47M= -github.com/goravel/framework v1.15.2/go.mod h1:Qo5Xlf+slrosyMxBKbNoxpEmzB6y2C5FI4BHNdVOSyI= -github.com/goravel/postgres v0.0.1 h1:M4KVxgdLmjMTlTz8iit5qMSihahWH6e8d0p4203r2kc= -github.com/goravel/postgres v0.0.1/go.mod h1:mBQwCDm/rcNZV6BiQoXeyDJiP/zZkVhWlX7PYdkEtG8= -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/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= -github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= -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/goravel/postgres v0.0.2-0.20250118135921-e5f4971c88a4 h1:Ib0Lrks2mCEvGk9nUdDr3rT+KrpScKamjXTz0SxJuzk= +github.com/goravel/postgres v0.0.2-0.20250118135921-e5f4971c88a4/go.mod h1:m0Sn/Vobu+8ADy6D2S+YENkZldp8X3E3Z3PoKaE9gfU= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= @@ -153,12 +70,6 @@ github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI= github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ= github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= -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= @@ -175,38 +86,11 @@ 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/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= -github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4= github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4= -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-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/microsoft/go-mssqldb v1.7.2/go.mod h1:kOvZKUdrhhFQmxLZqbwUV0rHkNkZpthMITIb2Ko1IoA= -github.com/microsoft/go-mssqldb v1.8.0 h1:7cyZ/AT7ycDsEoWPIXibd+aVKFtteUNhDGf3aobP+tw= -github.com/microsoft/go-mssqldb v1.8.0/go.mod h1:6znkekS3T2vp0waiMhen4GPU1BiAsrP+iXHcE7a7rFo= -github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= -github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= -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/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= -github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= -github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= -github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= -github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug= -github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= -github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= -github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= -github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -221,8 +105,6 @@ github.com/pterm/pterm v0.12.80 h1:mM55B+GnKUnLMUSqhdINe4s6tOuVQIetQ3my8JGyAIg= github.com/pterm/pterm v0.12.80/go.mod h1:c6DeF9bSnOSeFPZlfs4ZRAFcf5SCoTwvwQ5xaKGQlHo= github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E= github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw= -github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= -github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= @@ -237,18 +119,12 @@ github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVs github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y= github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 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.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= @@ -257,8 +133,6 @@ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJu github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 h1:TT4fX+nBOA/+LUkobKGW1ydGcn+G3vRw9+g5HwCphpk= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0/go.mod h1:L7UH0GbB0p47T4Rri3uHjbpCFYrVrwc1I25QhNPiGK8= go.opentelemetry.io/otel v1.33.0 h1:/FerN9bax5LoK51X/sI0SVYrjSE0/yUL7DpxW4K3FWw= go.opentelemetry.io/otel v1.33.0/go.mod h1:SUUkR6csvUQl+yjReHu5uM3EtVV7MBm5FHKRlNx4I8I= go.opentelemetry.io/otel/metric v1.33.0 h1:r+JOocAyeRVXD8lZpjdQjzMadVZp2M4WmQ+5WtEnklQ= @@ -269,39 +143,18 @@ go.opentelemetry.io/otel/sdk/metric v1.31.0 h1:i9hxxLJF/9kkvfHppyLL55aW7iIJz4Jjx go.opentelemetry.io/otel/sdk/metric v1.31.0/go.mod h1:CRInTMVvNhUKgSAMbKyTMxqOBC0zgyxzW55lZzX43Y8= go.opentelemetry.io/otel/trace v1.33.0 h1:cCJuF7LRjUFso9LPnEAHJDB2pqzp+hbO8eu1qqW2d/s= go.opentelemetry.io/otel/trace v1.33.0/go.mod h1:uIcdVUZMpTAmz0tI1z04GoVSezK37CbGV4fr1f2nBck= -go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= -go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= -golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= -golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= -golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= -golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 h1:yqrTHse8TCMW1M1ZCP+VAR/l0kKxwaAIqN/il7x4voA= golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8/go.mod h1:tujkw807nyEEAamNbDrEGzRav+ilXA7PCRAd6xsmwiU= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= -golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= 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-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= 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.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= -golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -314,7 +167,6 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/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-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -322,13 +174,6 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -336,24 +181,13 @@ golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9sn golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 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.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= -golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= -golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= -golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= -golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg= golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 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.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= @@ -361,23 +195,19 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE= -golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 h1:3UsHvIr4Wc2aW4brOaSCmcxh9ksica6fHEr8P1XhkYw= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422/go.mod h1:3ENsm/5D1mzDyhpzeRi1NR784I0BcofWBoSc5QqqMK4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f h1:OxYkA3wjPsZyBylwymxSHa7ViiW1Sml4ToBrncvFehI= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f/go.mod h1:+2Yz8+CLJbIfL9z73EW45avw8Lmge3xVElCP9zEKi50= google.golang.org/grpc v1.69.4 h1:MF5TftSMkd8GLw/m0KM6V8CMOCY6NZ1NQDPGFgbTt4A= -google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU= -google.golang.org/protobuf v1.36.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/grpc v1.69.4/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4= +google.golang.org/protobuf v1.36.3 h1:82DV7MYdb8anAVi3qge1wSnMDrnKK7ebr+I0hHRN1BU= +google.golang.org/protobuf v1.36.3/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -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.4/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/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.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= @@ -386,35 +216,8 @@ gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo= gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM= gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314= gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= -gorm.io/driver/sqlserver v1.5.4 h1:xA+Y1KDNspv79q43bPyjDMUgHoYHLhXYmdFcYPobg8g= -gorm.io/driver/sqlserver v1.5.4/go.mod h1:+frZ/qYmuna11zHPlh5oc2O6ZA/lS88Keb0XSH1Zh/g= -gorm.io/gorm v1.25.7-0.20240204074919-46816ad31dde/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= gorm.io/plugin/dbresolver v1.5.3 h1:wFwINGZZmttuu9h7XpvbDHd8Lf9bb8GNzp/NpAMV2wU= gorm.io/plugin/dbresolver v1.5.3/go.mod h1:TSrVhaUg2DZAWP3PrHlDlITEJmNOkL0tFTjvTEsQ4XE= -modernc.org/cc/v4 v4.24.4 h1:TFkx1s6dCkQpd6dKurBNmpo+G8Zl4Sq/ztJ+2+DEsh0= -modernc.org/cc/v4 v4.24.4/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0= -modernc.org/ccgo/v4 v4.23.10 h1:DnDZT/H6TtoJvQmVf7d8W+lVqEZpIJY/+0ENFh1LIHE= -modernc.org/ccgo/v4 v4.23.10/go.mod h1:vdN4h2WR5aEoNondUx26K7G8X+nuBscYnAEWSRmN2/0= -modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE= -modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ= -modernc.org/gc/v2 v2.6.1 h1:+Qf6xdG8l7B27TQ8D8lw/iFMUj1RXRBOuMUWziJOsk8= -modernc.org/gc/v2 v2.6.1/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito= -modernc.org/libc v1.61.7 h1:exz8rasFniviSgh3dH7QBnQHqYh9lolA5hVYfsiwkfo= -modernc.org/libc v1.61.7/go.mod h1:xspSrXRNVSfWfcfqgvZDVe/Hw5kv4FVC6IRfoms5v/0= -modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU= -modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg= -modernc.org/memory v1.8.1 h1:HS1HRg1jEohnuONobEq2WrLEhLyw8+J42yLFTnllm2A= -modernc.org/memory v1.8.1/go.mod h1:ZbjSvMO5NQ1A2i3bWeDiVMxIorXwdClKE/0SZ+BMotU= -modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8= -modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns= -modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w= -modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE= -modernc.org/sqlite v1.34.4 h1:sjdARozcL5KJBvYQvLlZEmctRgW9xqIZc2ncN7PU0P8= -modernc.org/sqlite v1.34.4/go.mod h1:3QQFCG2SEMtc2nv+Wq4cQCH7Hjcg+p/RMlS1XK+zwbk= -modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0= -modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A= -modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= -modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM= diff --git a/tests/orm_test.go b/tests/orm_test.go index 6c1715891..0fbea3080 100644 --- a/tests/orm_test.go +++ b/tests/orm_test.go @@ -26,6 +26,7 @@ func TestOrmSuite(t *testing.T) { func (s *OrmSuite) SetupSuite() { postgresTestQuery := postgresTestQuery("", false) + postgresTestQuery.CreateTable(TestTableRoles) s.queries[postgresTestQuery.Driver().Config().Connection] = postgresTestQuery s.defaultDriver = postgresTestQuery.Driver().Config().Driver } diff --git a/tests/query.go b/tests/query.go index c4c524ea9..90c8039db 100644 --- a/tests/query.go +++ b/tests/query.go @@ -6,12 +6,11 @@ import ( "slices" "github.com/goravel/framework/contracts/config" - "github.com/goravel/framework/contracts/database" - contractsdatabase "github.com/goravel/framework/contracts/database" "github.com/goravel/framework/contracts/database/driver" "github.com/goravel/framework/contracts/database/orm" "github.com/goravel/framework/database/gorm" "github.com/goravel/framework/testing/utils" + "github.com/goravel/postgres" ) type TestQuery struct { @@ -21,7 +20,7 @@ type TestQuery struct { } func NewTestQuery(ctx context.Context, driver driver.Driver, config config.Config) (*TestQuery, error) { - db, err := driver.Gorm() + db, gormQuery, err := driver.Gorm() if err != nil { return nil, err } @@ -29,14 +28,14 @@ func NewTestQuery(ctx context.Context, driver driver.Driver, config config.Confi testQuery := &TestQuery{ config: config, driver: driver, - query: gorm.NewQuery(ctx, config, driver.Config(), db, utils.NewTestLog(), nil, nil), + query: gorm.NewQuery(ctx, config, driver.Config(), db, gormQuery, utils.NewTestLog(), nil, nil), } return testQuery, nil } func (r *TestQuery) CreateTable(testTables ...TestTable) { - driverName := database.Driver(r.driver.Config().Driver) + driverName := r.driver.Config().Driver for table, sql := range newTestTables(driverName).All() { if (len(testTables) == 0 && table != TestTableSchema) || slices.Contains(testTables, table) { @@ -60,7 +59,8 @@ func (r *TestQuery) Query() orm.Query { } func (r *TestQuery) WithSchema(schema string) { - if r.driver.Config().Driver != contractsdatabase.DriverPostgres.String() && r.driver.Config().Driver != contractsdatabase.DriverSqlserver.String() { + // TODO: Add Sqlserver + if r.driver.Config().Driver != postgres.Name { panic(fmt.Sprintf("%s does not support schema", r.driver.Config().Driver)) } @@ -68,7 +68,8 @@ func (r *TestQuery) WithSchema(schema string) { panic(fmt.Sprintf("create schema %s failed: %v", schema, err)) } - if r.driver.Config().Driver == contractsdatabase.DriverSqlserver.String() { + // TODO Replace with sqlserver.Name + if r.driver.Config().Driver == "sqlserver" { return } diff --git a/tests/query_test.go b/tests/query_test.go index ebb8794d3..132536d05 100644 --- a/tests/query_test.go +++ b/tests/query_test.go @@ -33,6 +33,7 @@ func TestQueryTestSuite(t *testing.T) { func (s *QueryTestSuite) SetupSuite() { postgresTestQuery := postgresTestQuery("", false) + postgresTestQuery.CreateTable() s.queries[postgresTestQuery.Driver().Config().Driver] = postgresTestQuery } diff --git a/tests/schema_test.go b/tests/schema_test.go index 70ee0c347..f27b341ea 100644 --- a/tests/schema_test.go +++ b/tests/schema_test.go @@ -6,14 +6,13 @@ import ( "testing" "time" + contractsschema "github.com/goravel/framework/contracts/database/schema" + databaseschema "github.com/goravel/framework/database/schema" + "github.com/goravel/framework/support/carbon" + "github.com/goravel/postgres" "github.com/spf13/cast" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - - "github.com/goravel/framework/contracts/database" - contractsschema "github.com/goravel/framework/contracts/database/schema" - "github.com/goravel/framework/database/schema/constants" - "github.com/goravel/framework/support/carbon" ) type SchemaSuite struct { @@ -43,19 +42,21 @@ func (s *SchemaSuite) TearDownTest() { func (s *SchemaSuite) TestColumnChange() { for driver, testQuery := range s.driverToTestQuery { - if driver == database.DriverSqlite.String() { + // TODO Replace with sqlite.Name + if driver == "sqlite" { continue } s.Run(driver, func() { schema := newSchema(testQuery, s.driverToTestQuery) table := "column_change" - expectedDefaultStringLength := constants.DefaultStringLength + expectedDefaultStringLength := databaseschema.DefaultStringLength customStringLength := 100 expectedCustomStringLength := customStringLength expectedColumnType := "text" - if driver == database.DriverSqlserver.String() { - expectedDefaultStringLength = constants.DefaultStringLength * 2 + // TODO Replace with sqlserver.Name + if driver == "sqlserver" { + expectedDefaultStringLength = databaseschema.DefaultStringLength * 2 expectedCustomStringLength = customStringLength * 2 expectedColumnType = "nvarchar" } @@ -94,7 +95,8 @@ func (s *SchemaSuite) TestColumnChange() { if column.Name == "change_remove_default" || column.Name == "change_modify_default" { s.Contains(column.Default, "goravel") } - if driver != database.DriverSqlserver.String() { + // TODO Replace with sqlserver.Name + if driver != "sqlserver" { if column.Name == "change_add_comment" { s.Empty(column.Comment) } @@ -140,7 +142,8 @@ func (s *SchemaSuite) TestColumnChange() { if column.Name == "change_modify_default" { s.Contains(column.Default, "goravel_again") } - if driver != database.DriverSqlserver.String() { + // TODO Replace with sqlserver.Name + if driver != "sqlserver" { if column.Name == "change_add_comment" { s.Contains(column.Comment, "goravel") } @@ -217,7 +220,8 @@ func (s *SchemaSuite) TestColumnExtraAttributes() { s.NoError(testQuery.Query().Where("id", columnExtraAttribute.ID).First(&anotherColumnExtraAttribute)) s.Equal("world", anotherColumnExtraAttribute.Name) s.Equal(columnExtraAttribute.UseCurrent, anotherColumnExtraAttribute.UseCurrent) - if driver == database.DriverMysql.String() { + // TODO Replace with mysql.Name + if driver == "mysql" { s.NotEqual(columnExtraAttribute.UseCurrentOnUpdate, anotherColumnExtraAttribute.UseCurrentOnUpdate) s.True(anotherColumnExtraAttribute.UseCurrentOnUpdate.Between(now, carbon.Now().AddSecond())) } else { @@ -250,11 +254,11 @@ func (s *SchemaSuite) TestColumnMethods() { } func (s *SchemaSuite) TestColumnTypes_Postgres() { - if s.driverToTestQuery[database.DriverPostgres.String()] == nil { + if s.driverToTestQuery[postgres.Name] == nil { s.T().Skip("Skip test") } - testQuery := s.driverToTestQuery[database.DriverPostgres.String()] + testQuery := s.driverToTestQuery[postgres.Name] schema := newSchema(testQuery, s.driverToTestQuery) table := "postgres_columns" s.createTableAndAssertColumnsForColumnMethods(schema, table) @@ -573,11 +577,12 @@ func (s *SchemaSuite) TestColumnTypes_Postgres() { } func (s *SchemaSuite) TestColumnTypes_Sqlite() { - if s.driverToTestQuery[database.DriverSqlite.String()] == nil { + // TODO Replace with sqlite.Name + if s.driverToTestQuery["sqlite"] == nil { s.T().Skip("Skip test") } - testQuery := s.driverToTestQuery[database.DriverSqlite.String()] + testQuery := s.driverToTestQuery["sqlite"] schema := newSchema(testQuery, s.driverToTestQuery) table := "sqlite_columns" s.createTableAndAssertColumnsForColumnMethods(schema, table) @@ -854,11 +859,12 @@ func (s *SchemaSuite) TestColumnTypes_Sqlite() { } func (s *SchemaSuite) TestColumnTypes_Mysql() { - if s.driverToTestQuery[database.DriverMysql.String()] == nil { + // TODO Replace with mysql.Name + if s.driverToTestQuery["mysql"] == nil { s.T().Skip("Skip test") } - testQuery := s.driverToTestQuery[database.DriverMysql.String()] + testQuery := s.driverToTestQuery["mysql"] schema := newSchema(testQuery, s.driverToTestQuery) table := "mysql_columns" s.createTableAndAssertColumnsForColumnMethods(schema, table) @@ -1168,11 +1174,12 @@ func (s *SchemaSuite) TestColumnTypes_Mysql() { } func (s *SchemaSuite) TestColumnTypes_Sqlserver() { - if s.driverToTestQuery[database.DriverSqlserver.String()] == nil { + // TODO Replace with sqlserver.Name + if s.driverToTestQuery["sqlserver"] == nil { s.T().Skip("Skip test") } - testQuery := s.driverToTestQuery[database.DriverSqlserver.String()] + testQuery := s.driverToTestQuery["sqlserver"] schema := newSchema(testQuery, s.driverToTestQuery) table := "sqlserver_columns" s.createTableAndAssertColumnsForColumnMethods(schema, table) @@ -1482,11 +1489,11 @@ func (s *SchemaSuite) TestColumnTypes_Sqlserver() { } func (s *SchemaSuite) TestEnum_Postgres() { - if s.driverToTestQuery[database.DriverPostgres.String()] == nil { + if s.driverToTestQuery[postgres.Name] == nil { s.T().Skip("Skip test") } - testQuery := s.driverToTestQuery[database.DriverPostgres.String()] + testQuery := s.driverToTestQuery[postgres.Name] schema := newSchema(testQuery, s.driverToTestQuery) table := "postgres_enum" @@ -1517,11 +1524,12 @@ func (s *SchemaSuite) TestEnum_Postgres() { } func (s *SchemaSuite) TestEnum_Sqlite() { - if s.driverToTestQuery[database.DriverSqlite.String()] == nil { + // TODO Replace with sqlite.Name + if s.driverToTestQuery["sqlite"] == nil { s.T().Skip("Skip test") } - testQuery := s.driverToTestQuery[database.DriverSqlite.String()] + testQuery := s.driverToTestQuery["sqlite"] schema := newSchema(testQuery, s.driverToTestQuery) table := "sqlite_enum" @@ -1552,11 +1560,12 @@ func (s *SchemaSuite) TestEnum_Sqlite() { } func (s *SchemaSuite) TestEnum_Mysql() { - if s.driverToTestQuery[database.DriverMysql.String()] == nil { + // TODO Replace with mysql.Name + if s.driverToTestQuery["mysql"] == nil { s.T().Skip("Skip test") } - testQuery := s.driverToTestQuery[database.DriverMysql.String()] + testQuery := s.driverToTestQuery["mysql"] schema := newSchema(testQuery, s.driverToTestQuery) table := "mysql_enum" @@ -1587,11 +1596,12 @@ func (s *SchemaSuite) TestEnum_Mysql() { } func (s *SchemaSuite) TestEnum_Sqlserver() { - if s.driverToTestQuery[database.DriverSqlserver.String()] == nil { + // TODO Replace with sqlserver.Name + if s.driverToTestQuery["sqlserver"] == nil { s.T().Skip("Skip test") } - testQuery := s.driverToTestQuery[database.DriverSqlserver.String()] + testQuery := s.driverToTestQuery["sqlserver"] schema := newSchema(testQuery, s.driverToTestQuery) table := "sqlserver_enum" @@ -1666,7 +1676,8 @@ func (s *SchemaSuite) TestForeign() { s.ElementsMatch([]string{"id"}, foreignKey.ForeignColumns) s.Equal("no action", foreignKey.OnDelete) s.Equal("no action", foreignKey.OnUpdate) - if driver == database.DriverSqlite.String() { + // TODO Replace with sqlite.Name + if driver == "sqlite" { s.Empty(foreignKey.Name) s.Empty(foreignKey.ForeignSchema) } else { @@ -1678,7 +1689,8 @@ func (s *SchemaSuite) TestForeign() { s.ElementsMatch([]string{"id"}, foreignKey.ForeignColumns) s.Equal("cascade", foreignKey.OnDelete) s.Equal("cascade", foreignKey.OnUpdate) - if driver == database.DriverSqlite.String() { + // TODO Replace with sqlite.Name + if driver == "sqlite" { s.Empty(foreignKey.Name) s.Empty(foreignKey.ForeignSchema) } else { @@ -1699,7 +1711,8 @@ func (s *SchemaSuite) TestForeign() { foreignKeys, err = schema.GetForeignKeys(table3) s.NoError(err) - if driver == database.DriverSqlite.String() { + // TODO Replace with sqlite.Name + if driver == "sqlite" { s.Len(foreignKeys, 2) } else { s.Len(foreignKeys, 0) @@ -1722,7 +1735,8 @@ func (s *SchemaSuite) TestFullText() { s.Require().Nil(err) - if driver == database.DriverMysql.String() || driver == database.DriverPostgres.String() { + // TODO Replace with mysql.Name + if driver == "msyql" || driver == postgres.Name { s.True(schema.HasIndex(table, "goravel_fulltext_name_fulltext")) s.True(schema.HasIndex(table, "fulltext_avatar_fulltext")) } else { @@ -1755,26 +1769,30 @@ func (s *SchemaSuite) TestPrimary() { })) // SQLite does not support set primary index separately - if driver == database.DriverPostgres.String() { + if driver == postgres.Name { s.Require().True(schema.HasIndex(table, "goravel_primaries_pkey")) } - if driver == database.DriverMysql.String() { + // TODO Replace with mysql.Name + if driver == "mysql" { s.Require().True(schema.HasIndex(table, "primary")) } - if driver == database.DriverSqlserver.String() { + // TODO Replace with sqlserver.Name + if driver == "sqlserver" { s.Require().True(schema.HasIndex(table, "goravel_primaries_name_age_primary")) } s.NoError(schema.Table(table, func(table contractsschema.Blueprint) { table.DropPrimary("name", "age") })) - if driver == database.DriverPostgres.String() { + if driver == postgres.Name { s.Require().False(schema.HasIndex(table, "goravel_primaries_pkey")) } - if driver == database.DriverMysql.String() { + // TODO Replace with mysql.Name + if driver == "mysql" { s.Require().False(schema.HasIndex(table, "primary")) } - if driver == database.DriverSqlserver.String() { + // TODO Replace with sqlserver.Name + if driver == "sqlserver" { s.Require().False(schema.HasIndex(table, "goravel_primaries_name_age_primary")) } }) @@ -1782,11 +1800,11 @@ func (s *SchemaSuite) TestPrimary() { } func (s *SchemaSuite) TestID_Postgres() { - if s.driverToTestQuery[database.DriverPostgres.String()] == nil { + if s.driverToTestQuery[postgres.Name] == nil { s.T().Skip("Skip test") } - testQuery := s.driverToTestQuery[database.DriverPostgres.String()] + testQuery := s.driverToTestQuery[postgres.Name] schema := newSchema(testQuery, s.driverToTestQuery) tests := []struct { @@ -1874,11 +1892,12 @@ func (s *SchemaSuite) TestID_Postgres() { } func (s *SchemaSuite) TestID_Sqlite() { - if s.driverToTestQuery[database.DriverSqlite.String()] == nil { + // TODO Replace with sqlite.Name + if s.driverToTestQuery["sqlite"] == nil { s.T().Skip("Skip test") } - testQuery := s.driverToTestQuery[database.DriverSqlite.String()] + testQuery := s.driverToTestQuery["sqlite"] schema := newSchema(testQuery, s.driverToTestQuery) tests := []struct { @@ -1952,11 +1971,12 @@ func (s *SchemaSuite) TestID_Sqlite() { } func (s *SchemaSuite) TestID_Mysql() { - if s.driverToTestQuery[database.DriverMysql.String()] == nil { + // TODO Replace with mysql.Name + if s.driverToTestQuery["mysql"] == nil { s.T().Skip("Skip test") } - testQuery := s.driverToTestQuery[database.DriverMysql.String()] + testQuery := s.driverToTestQuery["mysql"] schema := newSchema(testQuery, s.driverToTestQuery) tests := []struct { @@ -2037,11 +2057,12 @@ func (s *SchemaSuite) TestID_Mysql() { } func (s *SchemaSuite) TestID_Sqlserver() { - if s.driverToTestQuery[database.DriverSqlserver.String()] == nil { + // TODO Replace with sqlserver.Name + if s.driverToTestQuery["sqlserver"] == nil { s.T().Skip("Skip test") } - testQuery := s.driverToTestQuery[database.DriverSqlserver.String()] + testQuery := s.driverToTestQuery["sqlserver"] schema := newSchema(testQuery, s.driverToTestQuery) tests := []struct { @@ -2147,9 +2168,9 @@ func (s *SchemaSuite) TestIndexMethods() { if index.Name == "goravel_indexes_id_name_index" { s.ElementsMatch(index.Columns, []string{"id", "name"}) s.False(index.Primary) - if driver == database.DriverSqlite.String() { + if driver == "sqlite" { s.Empty(index.Type) - } else if driver == database.DriverSqlserver.String() { + } else if driver == "sqlserver" { s.Equal("nonclustered", index.Type) } else { s.Equal("btree", index.Type) @@ -2159,9 +2180,9 @@ func (s *SchemaSuite) TestIndexMethods() { if index.Name == "name_index" { s.ElementsMatch(index.Columns, []string{"name"}) s.False(index.Primary) - if driver == database.DriverSqlite.String() { + if driver == "sqlite" { s.Empty(index.Type) - } else if driver == database.DriverSqlserver.String() { + } else if driver == "sqlserver" { s.Equal("nonclustered", index.Type) } else { s.Equal("btree", index.Type) @@ -2177,7 +2198,8 @@ func (s *SchemaSuite) TestIndexMethods() { if index.Name == "primary" { s.ElementsMatch(index.Columns, []string{"id"}) s.True(index.Primary) - if driver == database.DriverSqlite.String() { + // TODO Replace with sqlite.Name + if driver == "sqlite" { s.Empty(index.Type) } else { s.Equal("btree", index.Type) @@ -2227,7 +2249,8 @@ func (s *SchemaSuite) TestSql() { func (s *SchemaSuite) TestTypeMethods() { for driver, testQuery := range s.driverToTestQuery { - if driver != database.DriverPostgres.String() { + // TODO Add other drivers + if driver != postgres.Name { continue } @@ -2396,7 +2419,8 @@ func (s *SchemaSuite) TestViewMethods() { s.Equal("goravel_view", views[0].Name) s.NotEmpty(views[0].Definition) - if driver == database.DriverPostgres.String() || driver == database.DriverSqlserver.String() { + // TODO Replace with sqlserver.Name + if driver == postgres.Name || driver == "sqlserver" { s.NotEmpty(views[0].Schema) } else { s.Empty(views[0].Schema) @@ -2503,8 +2527,8 @@ func TestPostgresSchema(t *testing.T) { assert.NoError(t, err) assert.Len(t, tables, 1) assert.Equal(t, "table", tables[0].Name) - assert.Equal(t, newSchema, tables[0].Schema) - assert.True(t, newSchema.HasTable(fmt.Sprintf("%s.%s", newSchema, table))) + assert.Equal(t, "public", tables[0].Schema) + assert.True(t, newSchema.HasTable(fmt.Sprintf("public.%s", table))) assert.True(t, newSchema.HasTable(table)) } diff --git a/tests/table.go b/tests/table.go index 9e077f736..c6ebb7515 100644 --- a/tests/table.go +++ b/tests/table.go @@ -1,9 +1,5 @@ package tests -import ( - contractsdatabase "github.com/goravel/framework/contracts/database" -) - type TestTable int const ( @@ -23,10 +19,10 @@ const ( ) type testTables struct { - driver contractsdatabase.Driver + driver string } -func newTestTables(driver contractsdatabase.Driver) *testTables { +func newTestTables(driver string) *testTables { return &testTables{driver: driver} } @@ -50,7 +46,8 @@ func (r *testTables) All() map[TestTable]func() string { func (r *testTables) peoples() string { switch r.driver { - case contractsdatabase.DriverMysql: + // TODO Replace with mysql.Name + case "mysql": return ` CREATE TABLE peoples ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, @@ -63,7 +60,7 @@ CREATE TABLE peoples ( KEY idx_users_updated_at (updated_at) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; ` - case contractsdatabase.DriverPostgres: + case "postgres": return ` CREATE TABLE peoples ( id SERIAL PRIMARY KEY NOT NULL, @@ -73,7 +70,8 @@ CREATE TABLE peoples ( deleted_at timestamp DEFAULT NULL ); ` - case contractsdatabase.DriverSqlite: + // TODO Replace with sqlite.Name + case "sqlite": return ` CREATE TABLE peoples ( id integer PRIMARY KEY AUTOINCREMENT NOT NULL, @@ -83,7 +81,8 @@ CREATE TABLE peoples ( deleted_at datetime DEFAULT NULL ); ` - case contractsdatabase.DriverSqlserver: + // TODO Replace with sqlserver.Name + case "sqlserver": return ` CREATE TABLE peoples ( id bigint NOT NULL IDENTITY(1,1), @@ -101,7 +100,8 @@ CREATE TABLE peoples ( func (r *testTables) reviews() string { switch r.driver { - case contractsdatabase.DriverMysql: + // TODO Replace with mysql.Name + case "mysql": return ` CREATE TABLE reviews ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, @@ -114,7 +114,7 @@ CREATE TABLE reviews ( KEY idx_users_updated_at (updated_at) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; ` - case contractsdatabase.DriverPostgres: + case "postgres": return ` CREATE TABLE reviews ( id SERIAL PRIMARY KEY NOT NULL, @@ -124,7 +124,8 @@ CREATE TABLE reviews ( deleted_at timestamp DEFAULT NULL ); ` - case contractsdatabase.DriverSqlite: + // TODO Replace with sqlite.Name + case "sqlite": return ` CREATE TABLE reviews ( id integer PRIMARY KEY AUTOINCREMENT NOT NULL, @@ -134,7 +135,8 @@ CREATE TABLE reviews ( deleted_at datetime DEFAULT NULL ); ` - case contractsdatabase.DriverSqlserver: + // TODO Replace with sqlserver.Name + case "sqlserver": return ` CREATE TABLE reviews ( id bigint NOT NULL IDENTITY(1,1), @@ -152,7 +154,8 @@ CREATE TABLE reviews ( func (r *testTables) products() string { switch r.driver { - case contractsdatabase.DriverMysql: + // TODO Replace with mysql.Name + case "mysql": return ` CREATE TABLE products ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, @@ -165,7 +168,7 @@ CREATE TABLE products ( KEY idx_users_updated_at (updated_at) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; ` - case contractsdatabase.DriverPostgres: + case "postgres": return ` CREATE TABLE products ( id SERIAL PRIMARY KEY NOT NULL, @@ -175,7 +178,8 @@ CREATE TABLE products ( deleted_at timestamp DEFAULT NULL ); ` - case contractsdatabase.DriverSqlite: + // TODO Replace with sqlite.Name + case "sqlite": return ` CREATE TABLE products ( id integer PRIMARY KEY AUTOINCREMENT NOT NULL, @@ -185,7 +189,8 @@ CREATE TABLE products ( deleted_at datetime DEFAULT NULL ); ` - case contractsdatabase.DriverSqlserver: + // TODO Replace with sqlserver.Name + case "sqlserver": return ` CREATE TABLE products ( id bigint NOT NULL IDENTITY(1,1), @@ -203,7 +208,8 @@ CREATE TABLE products ( func (r *testTables) users() string { switch r.driver { - case contractsdatabase.DriverMysql: + // TODO Replace with mysql.Name + case "mysql": return ` CREATE TABLE users ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, @@ -218,7 +224,7 @@ CREATE TABLE users ( KEY idx_users_updated_at (updated_at) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; ` - case contractsdatabase.DriverPostgres: + case "postgres": return ` CREATE TABLE users ( id SERIAL PRIMARY KEY NOT NULL, @@ -230,7 +236,8 @@ CREATE TABLE users ( deleted_at timestamp DEFAULT NULL ); ` - case contractsdatabase.DriverSqlite: + // TODO Replace with sqlite.Name + case "sqlite": return ` CREATE TABLE users ( id integer PRIMARY KEY AUTOINCREMENT NOT NULL, @@ -242,7 +249,8 @@ CREATE TABLE users ( deleted_at datetime DEFAULT NULL ); ` - case contractsdatabase.DriverSqlserver: + // TODO Replace with sqlserver.Name + case "sqlserver": return ` CREATE TABLE users ( id bigint NOT NULL IDENTITY(1,1), @@ -262,7 +270,8 @@ CREATE TABLE users ( func (r *testTables) goravelUser() string { switch r.driver { - case contractsdatabase.DriverMysql: + // TODO Replace with mysql.Name + case "mysql": return ` CREATE TABLE goravel_user ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, @@ -277,7 +286,7 @@ CREATE TABLE goravel_user ( KEY idx_users_updated_at (updated_at) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; ` - case contractsdatabase.DriverPostgres: + case "postgres": return ` CREATE TABLE goravel_user ( id SERIAL PRIMARY KEY NOT NULL, @@ -289,7 +298,8 @@ CREATE TABLE goravel_user ( deleted_at timestamp DEFAULT NULL ); ` - case contractsdatabase.DriverSqlite: + // TODO Replace with sqlite.Name + case "sqlite": return ` CREATE TABLE goravel_user ( id integer PRIMARY KEY AUTOINCREMENT NOT NULL, @@ -301,7 +311,8 @@ CREATE TABLE goravel_user ( deleted_at datetime DEFAULT NULL ); ` - case contractsdatabase.DriverSqlserver: + // TODO Replace with sqlserver.Name + case "sqlserver": return ` CREATE TABLE goravel_user ( id bigint NOT NULL IDENTITY(1,1), @@ -321,7 +332,8 @@ CREATE TABLE goravel_user ( func (r *testTables) addresses() string { switch r.driver { - case contractsdatabase.DriverMysql: + // TODO Replace with mysql.Name + case "mysql": return ` CREATE TABLE addresses ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, @@ -335,7 +347,7 @@ CREATE TABLE addresses ( KEY idx_addresses_updated_at (updated_at) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; ` - case contractsdatabase.DriverPostgres: + case "postgres": return ` CREATE TABLE addresses ( id SERIAL PRIMARY KEY NOT NULL, @@ -346,7 +358,8 @@ CREATE TABLE addresses ( updated_at timestamp NOT NULL ); ` - case contractsdatabase.DriverSqlite: + // TODO Replace with sqlite.Name + case "sqlite": return ` CREATE TABLE addresses ( id integer PRIMARY KEY AUTOINCREMENT NOT NULL, @@ -357,7 +370,8 @@ CREATE TABLE addresses ( updated_at datetime NOT NULL ); ` - case contractsdatabase.DriverSqlserver: + // TODO Replace with sqlserver.Name + case "sqlserver": return ` CREATE TABLE addresses ( id bigint NOT NULL IDENTITY(1,1), @@ -376,7 +390,8 @@ CREATE TABLE addresses ( func (r *testTables) books() string { switch r.driver { - case contractsdatabase.DriverMysql: + // TODO Replace with mysql.Name + case "mysql": return ` CREATE TABLE books ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, @@ -389,7 +404,7 @@ CREATE TABLE books ( KEY idx_books_updated_at (updated_at) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; ` - case contractsdatabase.DriverPostgres: + case "postgres": return ` CREATE TABLE books ( id SERIAL PRIMARY KEY NOT NULL, @@ -399,7 +414,8 @@ CREATE TABLE books ( updated_at timestamp NOT NULL ); ` - case contractsdatabase.DriverSqlite: + // TODO Replace with sqlite.Name + case "sqlite": return ` CREATE TABLE books ( id integer PRIMARY KEY AUTOINCREMENT NOT NULL, @@ -409,7 +425,8 @@ CREATE TABLE books ( updated_at datetime NOT NULL ); ` - case contractsdatabase.DriverSqlserver: + // TODO Replace with sqlserver.Name + case "sqlserver": return ` CREATE TABLE books ( id bigint NOT NULL IDENTITY(1,1), @@ -427,7 +444,8 @@ CREATE TABLE books ( func (r *testTables) authors() string { switch r.driver { - case contractsdatabase.DriverMysql: + // TODO Replace with mysql.Name + case "mysql": return ` CREATE TABLE authors ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, @@ -440,7 +458,7 @@ CREATE TABLE authors ( KEY idx_books_updated_at (updated_at) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; ` - case contractsdatabase.DriverPostgres: + case "postgres": return ` CREATE TABLE authors ( id SERIAL PRIMARY KEY NOT NULL, @@ -450,7 +468,8 @@ CREATE TABLE authors ( updated_at timestamp NOT NULL ); ` - case contractsdatabase.DriverSqlite: + // TODO Replace with sqlite.Name + case "sqlite": return ` CREATE TABLE authors ( id integer PRIMARY KEY AUTOINCREMENT NOT NULL, @@ -460,7 +479,8 @@ CREATE TABLE authors ( updated_at datetime NOT NULL ); ` - case contractsdatabase.DriverSqlserver: + // TODO Replace with sqlserver.Name + case "sqlserver": return ` CREATE TABLE authors ( id bigint NOT NULL IDENTITY(1,1), @@ -478,7 +498,8 @@ CREATE TABLE authors ( func (r *testTables) roles() string { switch r.driver { - case contractsdatabase.DriverMysql: + // TODO Replace with mysql.Name + case "mysql": return ` CREATE TABLE roles ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, @@ -491,7 +512,7 @@ CREATE TABLE roles ( KEY idx_roles_updated_at (updated_at) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; ` - case contractsdatabase.DriverPostgres: + case "postgres": return ` CREATE TABLE roles ( id SERIAL PRIMARY KEY NOT NULL, @@ -501,7 +522,8 @@ CREATE TABLE roles ( updated_at timestamp NOT NULL ); ` - case contractsdatabase.DriverSqlite: + // TODO Replace with sqlite.Name + case "sqlite": return ` CREATE TABLE roles ( id integer PRIMARY KEY AUTOINCREMENT NOT NULL, @@ -511,7 +533,8 @@ CREATE TABLE roles ( updated_at datetime NOT NULL ); ` - case contractsdatabase.DriverSqlserver: + // TODO Replace with sqlserver.Name + case "sqlserver": return ` CREATE TABLE roles ( id bigint NOT NULL IDENTITY(1,1), @@ -529,7 +552,8 @@ CREATE TABLE roles ( func (r *testTables) houses() string { switch r.driver { - case contractsdatabase.DriverMysql: + // TODO Replace with mysql.Name + case "mysql": return ` CREATE TABLE houses ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, @@ -543,7 +567,7 @@ CREATE TABLE houses ( KEY idx_houses_updated_at (updated_at) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; ` - case contractsdatabase.DriverPostgres: + case "postgres": return ` CREATE TABLE houses ( id SERIAL PRIMARY KEY NOT NULL, @@ -554,7 +578,8 @@ CREATE TABLE houses ( updated_at timestamp NOT NULL ); ` - case contractsdatabase.DriverSqlite: + // TODO Replace with sqlite.Name + case "sqlite": return ` CREATE TABLE houses ( id integer PRIMARY KEY AUTOINCREMENT NOT NULL, @@ -565,7 +590,8 @@ CREATE TABLE houses ( updated_at datetime NOT NULL ); ` - case contractsdatabase.DriverSqlserver: + // TODO Replace with sqlserver.Name + case "sqlserver": return ` CREATE TABLE houses ( id bigint NOT NULL IDENTITY(1,1), @@ -584,7 +610,8 @@ CREATE TABLE houses ( func (r *testTables) phones() string { switch r.driver { - case contractsdatabase.DriverMysql: + // TODO Replace with mysql.Name + case "mysql": return ` CREATE TABLE phones ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, @@ -598,7 +625,7 @@ CREATE TABLE phones ( KEY idx_phones_updated_at (updated_at) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; ` - case contractsdatabase.DriverPostgres: + case "postgres": return ` CREATE TABLE phones ( id SERIAL PRIMARY KEY NOT NULL, @@ -609,7 +636,8 @@ CREATE TABLE phones ( updated_at timestamp NOT NULL ); ` - case contractsdatabase.DriverSqlite: + // TODO Replace with sqlite.Name + case "sqlite": return ` CREATE TABLE phones ( id integer PRIMARY KEY AUTOINCREMENT NOT NULL, @@ -620,7 +648,8 @@ CREATE TABLE phones ( updated_at datetime NOT NULL ); ` - case contractsdatabase.DriverSqlserver: + // TODO Replace with sqlserver.Name + case "sqlserver": return ` CREATE TABLE phones ( id bigint NOT NULL IDENTITY(1,1), @@ -639,7 +668,8 @@ CREATE TABLE phones ( func (r *testTables) roleUser() string { switch r.driver { - case contractsdatabase.DriverMysql: + // TODO Replace with mysql.Name + case "mysql": return ` CREATE TABLE role_user ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, @@ -648,7 +678,7 @@ CREATE TABLE role_user ( PRIMARY KEY (id) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; ` - case contractsdatabase.DriverPostgres: + case "postgres": return ` CREATE TABLE role_user ( id SERIAL PRIMARY KEY NOT NULL, @@ -656,7 +686,8 @@ CREATE TABLE role_user ( user_id int NOT NULL ); ` - case contractsdatabase.DriverSqlite: + // TODO Replace with sqlite.Name + case "sqlite": return ` CREATE TABLE role_user ( id integer PRIMARY KEY AUTOINCREMENT NOT NULL, @@ -664,7 +695,8 @@ CREATE TABLE role_user ( user_id int NOT NULL ); ` - case contractsdatabase.DriverSqlserver: + // TODO Replace with sqlserver.Name + case "sqlserver": return ` CREATE TABLE role_user ( id bigint NOT NULL IDENTITY(1,1), @@ -680,7 +712,8 @@ CREATE TABLE role_user ( func (r *testTables) schema() string { switch r.driver { - case contractsdatabase.DriverMysql: + // TODO Replace with mysql.Name + case "mysql": return ` CREATE TABLE goravel.schemas ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, @@ -692,7 +725,7 @@ CREATE TABLE goravel.schemas ( KEY idx_schemas_updated_at (updated_at) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; ` - case contractsdatabase.DriverPostgres: + case "postgres": return ` CREATE TABLE goravel.schemas ( id SERIAL PRIMARY KEY NOT NULL, @@ -701,7 +734,8 @@ CREATE TABLE goravel.schemas ( updated_at timestamp NOT NULL ); ` - case contractsdatabase.DriverSqlite: + // TODO Replace with sqlite.Name + case "sqlite": return ` CREATE TABLE goravel.schemas ( id integer PRIMARY KEY AUTOINCREMENT NOT NULL, @@ -710,7 +744,8 @@ CREATE TABLE goravel.schemas ( updated_at datetime NOT NULL ); ` - case contractsdatabase.DriverSqlserver: + // TODO Replace with sqlserver.Name + case "sqlserver": return ` CREATE TABLE goravel.schemas ( id bigint NOT NULL IDENTITY(1,1), diff --git a/tests/to_sql_test.go b/tests/to_sql_test.go index c6b41a00a..84452ff27 100644 --- a/tests/to_sql_test.go +++ b/tests/to_sql_test.go @@ -23,7 +23,7 @@ func TestToSqlTestSuite(t *testing.T) { func (s *ToSqlTestSuite) SetupSuite() { postgresTestQuery := postgresTestQuery("", false) - + postgresTestQuery.CreateTable(TestTableUsers) s.query = postgresTestQuery.Query() } diff --git a/tests/utils.go b/tests/utils.go index 44593d9c0..8c9aad4a4 100644 --- a/tests/utils.go +++ b/tests/utils.go @@ -39,13 +39,12 @@ func postgresTestQuery(prefix string, singular bool) *TestQuery { mockConfig.EXPECT().GetInt("database.pool.max_open_conns", 100).Return(100) mockConfig.EXPECT().GetInt("database.pool.conn_max_idletime", 3600).Return(3600) mockConfig.EXPECT().GetInt("database.pool.conn_max_lifetime", 3600).Return(3600) - mockConfig.EXPECT().Get("database.connections.postgres.read").Return(nil) mockConfig.EXPECT().Get("database.connections.postgres.write").Return(nil) - mockConfig.EXPECT().GetString("database.connections.postgres.host").Return("localhost") + mockConfig.EXPECT().GetString("database.connections.postgres.host").Return(postgresContainer.Config().Host) mockConfig.EXPECT().GetInt("database.connections.postgres.port").Return(postgresContainer.Config().Port) - mockConfig.EXPECT().GetString("database.connections.postgres.username").Return(testUsername) - mockConfig.EXPECT().GetString("database.connections.postgres.password").Return(testPassword) + mockConfig.EXPECT().GetString("database.connections.postgres.username").Return(postgresContainer.Config().Username) + mockConfig.EXPECT().GetString("database.connections.postgres.password").Return(postgresContainer.Config().Password) mockConfig.EXPECT().GetString("database.connections.postgres.database").Return(postgresContainer.Config().Database) mockConfig.EXPECT().GetString("database.connections.postgres.sslmode").Return("disable") mockConfig.EXPECT().GetString("database.connections.postgres.timezone").Return("UTC") @@ -56,7 +55,7 @@ func postgresTestQuery(prefix string, singular bool) *TestQuery { mockConfig.EXPECT().GetString("database.connections.postgres.schema", "public").Return("public") mockConfig.EXPECT().Get("database.connections.postgres.name_replacer").Return(nil) mockConfig.EXPECT().Get("database.connections.postgres.via").Return(func() (driver.Driver, error) { - return nil, nil + return postgres.NewPostgres(mockConfig, utils.NewTestLog(), "postgres"), nil }) mockConfig.EXPECT().Add("database.connections.postgres.schema", testSchema) @@ -68,8 +67,6 @@ func postgresTestQuery(prefix string, singular bool) *TestQuery { panic(err) } - testQuery.CreateTable() - return testQuery }