Skip to content

Commit

Permalink
moved broken models directory
Browse files Browse the repository at this point in the history
  • Loading branch information
dorav committed Dec 17, 2023
1 parent 153b406 commit 20f8ce0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
11 changes: 6 additions & 5 deletions gormschema/gorm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"testing"

"ariga.io/atlas-go-sdk/recordriver"
ckModels "ariga.io/atlas-provider-gorm/internal/testdata/circular_fk_models"
"ariga.io/atlas-provider-gorm/internal/testdata/models"
"github.com/stretchr/testify/require"
"gorm.io/gorm"
)

func TestSQLiteConfig(t *testing.T) {
l := New("sqlite")
sql, err := l.Load(models.Pet{}, models.User{}, models.Event{}, models.Location{})
sql, err := l.Load(models.Pet{}, models.User{}, ckModels.Event{}, ckModels.Location{})
require.NoError(t, err)
require.Contains(t, sql, "CREATE TABLE `pets`")
require.Contains(t, sql, "CREATE TABLE `users`")
Expand Down Expand Up @@ -49,7 +50,7 @@ func TestPostgreSQLConfig(t *testing.T) {
resetSession(t)
l = New("postgres",
WithCreateConstraintsAfterCreateTable(true))
sql, err = l.Load(models.Location{}, models.Event{})
sql, err = l.Load(ckModels.Location{}, ckModels.Event{})
require.NoError(t, err)
require.Contains(t, sql, `CREATE TABLE "events"`)
require.Contains(t, sql, `CREATE UNIQUE INDEX IF NOT EXISTS "idx_events_location_id"`)
Expand All @@ -62,7 +63,7 @@ func TestPostgreSQLConfig(t *testing.T) {
&gorm.Config{
DisableForeignKeyConstraintWhenMigrating: true,
}))
sql, err = l.Load(models.Location{}, models.Event{})
sql, err = l.Load(ckModels.Location{}, ckModels.Event{})
require.NoError(t, err)
require.Contains(t, sql, `CREATE TABLE "events"`)
require.Contains(t, sql, `CREATE TABLE "locations"`)
Expand All @@ -80,7 +81,7 @@ func TestMySQLConfig(t *testing.T) {
resetSession(t)
l = New("mysql",
WithCreateConstraintsAfterCreateTable(true))
sql, err = l.Load(models.Location{}, models.Event{})
sql, err = l.Load(ckModels.Location{}, ckModels.Event{})
require.NoError(t, err)
require.Contains(t, sql, "CREATE TABLE `events`")
require.Contains(t, sql, "CREATE TABLE `locations`")
Expand All @@ -92,7 +93,7 @@ func TestMySQLConfig(t *testing.T) {
DisableForeignKeyConstraintWhenMigrating: true,
},
))
sql, err = l.Load(models.Location{}, models.Event{})
sql, err = l.Load(ckModels.Location{}, ckModels.Event{})
require.NoError(t, err)
require.Contains(t, sql, "CREATE TABLE `events`")
require.Contains(t, sql, "CREATE TABLE `locations`")
Expand Down
13 changes: 13 additions & 0 deletions internal/testdata/circular_fk_models/models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package circular_fk_models

type Location struct {
LocationID string `gorm:"primaryKey;column:locationId;"`
EventID string `gorm:"uniqueIndex;column:eventId;"`
Event *Event `gorm:"foreignKey:locationId;references:locationId;OnUpdate:CASCADE,OnDelete:CASCADE"`
}

type Event struct {
EventID string `gorm:"primaryKey;column:eventId;"`
LocationID string `gorm:"uniqueIndex;column:locationId;"`
Location *Location `gorm:"foreignKey:eventId;references:eventId;OnUpdate:CASCADE,OnDelete:CASCADE"`
}
12 changes: 0 additions & 12 deletions internal/testdata/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,3 @@ type Toy struct {
ID uint
Name string
}

type Location struct {
LocationID string `gorm:"primaryKey;column:locationId;"`
EventID string `gorm:"uniqueIndex;column:eventId;"`
Event *Event `gorm:"foreignKey:locationId;references:locationId;OnUpdate:CASCADE,OnDelete:CASCADE"`
}

type Event struct {
EventID string `gorm:"primaryKey;column:eventId;"`
LocationID string `gorm:"uniqueIndex;column:locationId;"`
Location *Location `gorm:"foreignKey:eventId;references:eventId;OnUpdate:CASCADE,OnDelete:CASCADE"`
}

0 comments on commit 20f8ce0

Please sign in to comment.