Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/kkumar-gcc/#441-5' into kkumar-gcc/
Browse files Browse the repository at this point in the history
  • Loading branch information
kkumar-gcc committed Nov 17, 2024
2 parents e652ad0 + f0e775f commit ac2f10b
Show file tree
Hide file tree
Showing 59 changed files with 2,048 additions and 478 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
.idea
.DS_Store
.vscode
goravel*
/vendor
2 changes: 2 additions & 0 deletions contracts/database/orm/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type Orm interface {
DB() (*sql.DB, error)
// Factory gets a new factory instance for the given model name.
Factory() Factory
// DatabaseName gets the current database name.
DatabaseName() string
// Name gets the current connection name.
Name() string
// Observe registers an observer with the Orm.
Expand Down
10 changes: 8 additions & 2 deletions contracts/database/schema/blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import (
)

type Blueprint interface {
// BigIncrements Create a new auto-incrementing big integer (8-byte) column on the table.
BigIncrements(column string) ColumnDefinition
// BigInteger Create a new big integer (8-byte) column on the table.
BigInteger(column string) ColumnDefinition
// Build Execute the blueprint to build / modify the table.
Build(query orm.Query, grammar Grammar) error
// Create Indicate that the table needs to be created.
Expand All @@ -21,20 +25,22 @@ type Blueprint interface {
GetTableName() string
// HasCommand Determine if the blueprint has a specific command.
HasCommand(command string) bool
// Primary Specify the primary key(s) for the table.
Primary(column ...string)
// ID Create a new auto-incrementing big integer (8-byte) column on the table.
ID(column ...string) ColumnDefinition
// Index Specify an index for the table.
Index(column ...string) IndexDefinition
// Integer Create a new integer (4-byte) column on the table.
Integer(column string) ColumnDefinition
// Primary Specify the primary key(s) for the table.
Primary(column ...string)
// SetTable Set the table that the blueprint operates on.
SetTable(name string)
// String Create a new string column on the table.
String(column string, length ...int) ColumnDefinition
// ToSql Get the raw SQL statements for the blueprint.
ToSql(grammar Grammar) []string
// UnsignedBigInteger Create a new unsigned big integer (8-byte) column on the table.
UnsignedBigInteger(column string) ColumnDefinition
}

type IndexConfig struct {
Expand Down
4 changes: 2 additions & 2 deletions contracts/database/schema/grammar.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ type Grammar interface {
// CompilePrimary Compile a primary key command.
CompilePrimary(blueprint Blueprint, command *Command) string
// CompileTables Compile the query to determine the tables.
CompileTables() string
CompileTables(database string) string
// CompileTypes Compile the query to determine the types.
CompileTypes() string
// CompileViews Compile the query to determine the views.
CompileViews() string
CompileViews(database string) string
// GetAttributeCommands Get the commands for the schema build.
GetAttributeCommands() []string
// TypeBigInteger Create the column definition for a big integer type.
Expand Down
25 changes: 13 additions & 12 deletions contracts/database/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,19 @@ type Connection interface {
}

type Command struct {
Algorithm string
Column ColumnDefinition
Columns []string
From string
Index string
On string
OnDelete string
OnUpdate string
Name string
To string
References []string
Value string
Algorithm string
Column ColumnDefinition
Columns []string
From string
Index string
On string
OnDelete string
OnUpdate string
Name string
To string
References []string
ShouldBeSkipped bool
Value string
}

type Index struct {
Expand Down
22 changes: 14 additions & 8 deletions contracts/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,32 @@ type Database interface {
}

type DatabaseDriver interface {
// Build the database.
// Build a database container, it doesn't wait for the database to be ready, the Ready method needs to be called if
// you want to check the container status.
Build() error
// Config get database configuration.
Config() DatabaseConfig
// Database returns a new instance with a new database, the Build method needs to be called first.
Database(name string) (DatabaseDriver, error)
// Driver gets the database driver name.
Driver() database.Driver
// Fresh the database.
Fresh() error
// Image gets the database image.
Image(image Image)
// Driver gets the database driver name.
Driver() database.Driver
// Ready checks if the database is ready, the Build method needs to be called first.
Ready() error
// Stop the database.
Stop() error
}

type DatabaseConfig struct {
Host string
Port int
Database string
Username string
Password string
Host string
Port int
Database string
Username string
Password string
ContainerID string
}

type Image struct {
Expand Down
7 changes: 5 additions & 2 deletions database/factory/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,17 @@ type FactoryTestSuite struct {

func TestFactoryTestSuite(t *testing.T) {
if env.IsWindows() {
t.Skip("Skipping tests that use Docker")
t.Skip("Skip test that using Docker")
}

suite.Run(t, &FactoryTestSuite{})
}

func (s *FactoryTestSuite) SetupSuite() {
postgresQuery := gorm.NewTestQuery(docker.Postgres())
postgresDocker := docker.Postgres()
s.Require().NoError(postgresDocker.Ready())

postgresQuery := gorm.NewTestQuery(postgresDocker)
postgresQuery.CreateTable(gorm.TestTableHouses, gorm.TestTableUsers)

s.query = postgresQuery.Query()
Expand Down
36 changes: 24 additions & 12 deletions database/gorm/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type QueryTestSuite struct {

func TestQueryTestSuite(t *testing.T) {
if env.IsWindows() {
t.Skip("Skipping tests that use Docker")
t.Skip("Skip test that using Docker")
}

suite.Run(t, &QueryTestSuite{})
Expand All @@ -52,6 +52,12 @@ func (s *QueryTestSuite) SetupSuite() {

func (s *QueryTestSuite) SetupTest() {}

func (s *QueryTestSuite) TearDownSuite() {
if s.queries[database.DriverSqlite] != nil {
s.NoError(s.queries[database.DriverSqlite].Docker().Stop())
}
}

func (s *QueryTestSuite) TestAssociation() {
for driver, query := range s.queries {
tests := []struct {
Expand Down Expand Up @@ -3538,7 +3544,7 @@ func (s *QueryTestSuite) TestWith() {
setup: func(description string) {
var user1 User
s.Nil(query.Query().With("Books", func(query contractsorm.Query) contractsorm.Query {
return query.Where("name = ?", "with_book0")
return query.Where("name = ?", "with_book0").Select("id", "user_id", "name")
}).Find(&user1, user.ID))
s.True(user1.ID > 0)
s.Nil(user1.Address)
Expand Down Expand Up @@ -3589,10 +3595,12 @@ func (s *QueryTestSuite) TestWithNesting() {

func TestCustomConnection(t *testing.T) {
if env.IsWindows() {
t.Skip("Skipping tests that use Docker")
t.Skip("Skip test that using Docker")
}

postgresDocker := supportdocker.Postgres()
require.NoError(t, postgresDocker.Ready())

postgresQuery := NewTestQuery(postgresDocker)
postgresQuery.CreateTable(TestTableReviews, TestTableProducts)

Expand Down Expand Up @@ -3629,6 +3637,8 @@ func TestCustomConnection(t *testing.T) {
person := Person{Name: "create_person"}
assert.NotNil(t, query.Create(&person))
assert.True(t, person.ID == 0)

assert.NoError(t, sqliteDocker.Stop())
}

func TestFilterFindConditions(t *testing.T) {
Expand Down Expand Up @@ -3751,7 +3761,7 @@ func TestObserverEvent(t *testing.T) {

func TestReadWriteSeparate(t *testing.T) {
if env.IsWindows() {
t.Skip("Skipping tests that use Docker")
t.Skip("Skip test that using Docker")
}

dbs := NewTestQueries().QueriesOfReadWrite()
Expand All @@ -3763,14 +3773,9 @@ func TestReadWriteSeparate(t *testing.T) {
err error
)
if drive == database.DriverSqlite {
mixQuery, err = db["write"].QueryOfReadWrite(TestReadWriteConfig{
ReadDatabase: db["read"].Docker().Config().Database,
})
mixQuery, err = db["write"].QueryOfReadWrite(db["read"].Docker().Config())
} else {
mixQuery, err = db["write"].QueryOfReadWrite(TestReadWriteConfig{
ReadPort: db["read"].Docker().Config().Port,
WritePort: db["write"].Docker().Config().Port,
})
mixQuery, err = db["write"].QueryOfReadWrite(db["read"].Docker().Config())
}

require.NoError(t, err)
Expand All @@ -3795,11 +3800,14 @@ func TestReadWriteSeparate(t *testing.T) {
assert.True(t, user4.ID > 0)
})
}

assert.NoError(t, dbs[database.DriverSqlite]["read"].Docker().Stop())
assert.NoError(t, dbs[database.DriverSqlite]["write"].Docker().Stop())
}

func TestTablePrefixAndSingular(t *testing.T) {
if env.IsWindows() {
t.Skip("Skipping tests that use Docker")
t.Skip("Skip test that using Docker")
}

dbs := NewTestQueries().QueriesWithPrefixAndSingular()
Expand All @@ -3817,6 +3825,10 @@ func TestTablePrefixAndSingular(t *testing.T) {
assert.True(t, user1.ID > 0)
})
}

if dbs[database.DriverSqlite] != nil {
assert.NoError(t, dbs[database.DriverSqlite].Docker().Stop())
}
}

func paginator(page string, limit string) func(methods contractsorm.Query) contractsorm.Query {
Expand Down
Loading

0 comments on commit ac2f10b

Please sign in to comment.