Skip to content

Commit 4108c22

Browse files
committed
Remove
1 parent 67447fd commit 4108c22

File tree

9 files changed

+9
-185
lines changed

9 files changed

+9
-185
lines changed

contracts/database/schema/blueprint.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ type Blueprint interface {
1313
DropIfExists()
1414
// GetAddedColumns Get the added columns.
1515
GetAddedColumns() []ColumnDefinition
16-
// GetChangedColumns Get the changed columns.
17-
//GetChangedColumns() []ColumnDefinition
1816
// GetCommands Get the commands.
1917
GetCommands() []*Command
2018
// GetTableName Get the table name with prefix.

contracts/database/schema/column.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@ package schema
33
type ColumnDefinition interface {
44
// AutoIncrement set the column as auto increment
55
AutoIncrement() ColumnDefinition
6-
// Change the column
7-
//Change()
86
// GetAutoIncrement returns the autoIncrement value
97
GetAutoIncrement() bool
10-
// GetChange returns the change value
11-
//GetChange() bool
128
// GetDefault returns the default value
139
GetDefault() any
1410
// GetLength returns the length value

contracts/database/schema/grammar.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
type Grammar interface {
88
// CompileAdd Compile an add column command.
99
CompileAdd(blueprint Blueprint, command *Command) string
10-
// CompileChange Compile a change column command into a series of SQL statements.
11-
CompileChange(blueprint Blueprint, command *Command) string
1210
// CompileCreate Compile a create table command.
1311
CompileCreate(blueprint Blueprint, query orm.Query) string
1412
// CompileDropAllDomains Compile the SQL needed to drop all domains.

database/schema/blueprint.go

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,11 @@ func (r *Blueprint) GetAddedColumns() []schema.ColumnDefinition {
6262
var columns []schema.ColumnDefinition
6363
for _, column := range r.columns {
6464
columns = append(columns, column)
65-
//if column.change == nil || !*column.change {
66-
// columns = append(columns, column)
67-
//}
6865
}
6966

7067
return columns
7168
}
7269

73-
//func (r *Blueprint) GetChangedColumns() []schema.ColumnDefinition {
74-
// var columns []schema.ColumnDefinition
75-
// for _, column := range r.columns {
76-
// if column.change != nil && *column.change {
77-
// columns = append(columns, column)
78-
// }
79-
// }
80-
//
81-
// return columns
82-
//}
83-
8470
func (r *Blueprint) GetCommands() []*schema.Command {
8571
return r.commands
8672
}
@@ -147,8 +133,6 @@ func (r *Blueprint) ToSql(query ormcontract.Query, grammar schema.Grammar) []str
147133
switch command.Name {
148134
case constants.CommandAdd:
149135
statements = append(statements, grammar.CompileAdd(r, command))
150-
case constants.CommandChange:
151-
statements = append(statements, grammar.CompileChange(r, command))
152136
case constants.CommandCreate:
153137
statements = append(statements, grammar.CompileCreate(r, query))
154138
case constants.CommandDropIfExists:
@@ -181,15 +165,8 @@ func (r *Blueprint) addColumn(column *ColumnDefinition) {
181165
r.columns = append(r.columns, column)
182166

183167
if !r.isCreate() {
184-
//var name string
185-
//if column.GetChange() {
186-
// name = constants.CommandChange
187-
//} else {
188-
// name = constants.CommandAdd
189-
//}
190-
name := constants.CommandAdd
191168
r.addCommand(&schema.Command{
192-
Name: name,
169+
Name: constants.CommandAdd,
193170
Column: column,
194171
})
195172
}

database/schema/blueprint_test.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -142,35 +142,12 @@ func (s *BlueprintTestSuite) TestGetAddedColumns() {
142142
name: &name,
143143
}
144144

145-
//change := true
146-
//changedColumn := &ColumnDefinition{
147-
// change: &change,
148-
// name: &name,
149-
//}
150-
151145
s.blueprint.columns = []*ColumnDefinition{addedColumn}
152146

153147
s.Len(s.blueprint.GetAddedColumns(), 1)
154148
s.Equal(addedColumn, s.blueprint.GetAddedColumns()[0])
155149
}
156150

157-
//func (s *BlueprintTestSuite) TestGetChangedColumns() {
158-
// name := "name"
159-
// change := true
160-
// addedColumn := &ColumnDefinition{
161-
// name: &name,
162-
// }
163-
// changedColumn := &ColumnDefinition{
164-
// change: &change,
165-
// name: &name,
166-
// }
167-
//
168-
// s.blueprint.columns = []*ColumnDefinition{addedColumn, changedColumn}
169-
//
170-
// s.Len(s.blueprint.GetChangedColumns(), 1)
171-
// s.Equal(changedColumn, s.blueprint.GetChangedColumns()[0])
172-
//}
173-
174151
func (s *BlueprintTestSuite) TestGetTableName() {
175152
s.blueprint.SetTable("users")
176153
s.Equal("goravel_users", s.blueprint.GetTableName())

database/schema/column.go

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ import (
77

88
type ColumnDefinition struct {
99
autoIncrement *bool
10-
//change *bool
11-
comment *string
12-
def any
13-
length *int
14-
name *string
15-
nullable *bool
16-
ttype *string
17-
unsigned *bool
10+
comment *string
11+
def any
12+
length *int
13+
name *string
14+
nullable *bool
15+
ttype *string
16+
unsigned *bool
1817
}
1918

2019
func (r *ColumnDefinition) AutoIncrement() schema.ColumnDefinition {
@@ -23,10 +22,6 @@ func (r *ColumnDefinition) AutoIncrement() schema.ColumnDefinition {
2322
return r
2423
}
2524

26-
//func (r *ColumnDefinition) Change() {
27-
// r.change = convert.Pointer(true)
28-
//}
29-
3025
func (r *ColumnDefinition) GetAutoIncrement() (autoIncrement bool) {
3126
if r.autoIncrement != nil {
3227
return *r.autoIncrement
@@ -35,14 +30,6 @@ func (r *ColumnDefinition) GetAutoIncrement() (autoIncrement bool) {
3530
return
3631
}
3732

38-
//func (r *ColumnDefinition) GetChange() (change bool) {
39-
// if r.change != nil {
40-
// return *r.change
41-
// }
42-
//
43-
// return
44-
//}
45-
4633
func (r *ColumnDefinition) GetDefault() any {
4734
return r.def
4835
}

database/schema/column_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ func (s *ColumnDefinitionTestSuite) GetAutoIncrement() {
2828
s.True(s.columnDefinition.GetAutoIncrement())
2929
}
3030

31-
func (s *ColumnDefinitionTestSuite) GetChange() {
32-
s.False(s.columnDefinition.GetChange())
33-
34-
s.columnDefinition.change = convert.Pointer(true)
35-
s.True(s.columnDefinition.GetChange())
36-
}
37-
3831
func (s *ColumnDefinitionTestSuite) GetDefault() {
3932
s.Nil(s.columnDefinition.GetDefault())
4033

database/schema/grammars/postgres.go

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,6 @@ func (r *Postgres) CompileAdd(blueprint schema.Blueprint, command *schema.Comman
3434
return fmt.Sprintf("alter table %s add column %s", blueprint.GetTableName(), getColumn(r, blueprint, command.Column))
3535
}
3636

37-
func (r *Postgres) CompileChange(blueprint schema.Blueprint, command *schema.Command) string {
38-
var changes []string
39-
40-
for _, modifier := range r.modifiers {
41-
if change := modifier(blueprint, command.Column); change != "" {
42-
changes = append(changes, change)
43-
}
44-
}
45-
46-
column := strings.Join(prefixArray("alter column "+command.Column.GetName(), changes), ", ")
47-
48-
return fmt.Sprintf("alter table %s %s", blueprint.GetTableName(), column)
49-
}
50-
5137
func (r *Postgres) CompileCreate(blueprint schema.Blueprint, query orm.Query) string {
5238
return fmt.Sprintf("create table %s (%s)", blueprint.GetTableName(), strings.Join(getColumns(r, blueprint), ","))
5339
}
@@ -120,18 +106,6 @@ func (r *Postgres) GetModifiers() []func(blueprint schema.Blueprint, column sche
120106
}
121107

122108
func (r *Postgres) ModifyDefault(blueprint schema.Blueprint, column schema.ColumnDefinition) string {
123-
if column.GetChange() {
124-
if !column.GetAutoIncrement() {
125-
if column.GetDefault() == nil {
126-
return "drop default"
127-
} else {
128-
return fmt.Sprintf("set default %s", getDefaultValue(column.GetDefault()))
129-
}
130-
}
131-
132-
return ""
133-
}
134-
135109
if column.GetDefault() != nil {
136110
return fmt.Sprintf(" default %s", getDefaultValue(column.GetDefault()))
137111
}
@@ -140,14 +114,6 @@ func (r *Postgres) ModifyDefault(blueprint schema.Blueprint, column schema.Colum
140114
}
141115

142116
func (r *Postgres) ModifyNullable(blueprint schema.Blueprint, column schema.ColumnDefinition) string {
143-
if column.GetChange() {
144-
if column.GetNullable() {
145-
return "drop not null"
146-
} else {
147-
return "set not null"
148-
}
149-
}
150-
151117
if column.GetNullable() {
152118
return " null"
153119
} else {
@@ -156,7 +122,7 @@ func (r *Postgres) ModifyNullable(blueprint schema.Blueprint, column schema.Colu
156122
}
157123

158124
func (r *Postgres) ModifyIncrement(blueprint schema.Blueprint, column schema.ColumnDefinition) string {
159-
if !column.GetChange() && !blueprint.HasCommand("primary") && slices.Contains(r.serials, column.GetType()) && column.GetAutoIncrement() {
125+
if !blueprint.HasCommand("primary") && slices.Contains(r.serials, column.GetType()) && column.GetAutoIncrement() {
160126
return " primary key"
161127
}
162128

database/schema/grammars/postgres_test.go

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ func (s *PostgresSuite) TestCompileAdd() {
3030
mockColumn.EXPECT().GetName().Return("name").Once()
3131
mockColumn.EXPECT().GetType().Return("string").Twice()
3232
mockColumn.EXPECT().GetDefault().Return("goravel").Twice()
33-
mockColumn.EXPECT().GetChange().Return(false).Times(3)
3433
mockColumn.EXPECT().GetNullable().Return(false).Once()
3534
mockColumn.EXPECT().GetLength().Return(1).Once()
3635
mockBlueprint.EXPECT().HasCommand("primary").Return(false).Once()
@@ -42,24 +41,6 @@ func (s *PostgresSuite) TestCompileAdd() {
4241
s.Equal("alter table users add column name varchar(1) default 'goravel' not null", sql)
4342
}
4443

45-
func (s *PostgresSuite) TestCompileChange() {
46-
mockBlueprint := mocksschema.NewBlueprint(s.T())
47-
mockColumn := mocksschema.NewColumnDefinition(s.T())
48-
49-
mockBlueprint.EXPECT().GetTableName().Return("users").Once()
50-
mockColumn.EXPECT().GetAutoIncrement().Return(false).Once()
51-
mockColumn.EXPECT().GetDefault().Return("goravel").Twice()
52-
mockColumn.EXPECT().GetName().Return("name").Once()
53-
mockColumn.EXPECT().GetChange().Return(true).Times(3)
54-
mockColumn.EXPECT().GetNullable().Return(true).Once()
55-
56-
sql := s.grammar.CompileChange(mockBlueprint, &contractsschema.Command{
57-
Column: mockColumn,
58-
})
59-
60-
s.Equal("alter table users alter column name set default 'goravel', alter column name drop not null", sql)
61-
}
62-
6344
func (s *PostgresSuite) TestCompileCreate() {
6445
mockColumn1 := mocksschema.NewColumnDefinition(s.T())
6546
mockColumn2 := mocksschema.NewColumnDefinition(s.T())
@@ -78,15 +59,12 @@ func (s *PostgresSuite) TestCompileCreate() {
7859
// postgres.go::TypeInteger
7960
mockColumn1.EXPECT().GetAutoIncrement().Return(true).Once()
8061
// postgres.go::ModifyDefault
81-
mockColumn1.EXPECT().GetChange().Return(false).Once()
8262
mockColumn1.EXPECT().GetDefault().Return(nil).Once()
8363
// postgres.go::ModifyIncrement
84-
mockColumn1.EXPECT().GetChange().Return(false).Once()
8564
mockBlueprint.EXPECT().HasCommand("primary").Return(false).Once()
8665
mockColumn1.EXPECT().GetType().Return("integer").Once()
8766
mockColumn1.EXPECT().GetAutoIncrement().Return(true).Once()
8867
// postgres.go::ModifyNullable
89-
mockColumn1.EXPECT().GetChange().Return(false).Once()
9068
mockColumn1.EXPECT().GetNullable().Return(false).Once()
9169

9270
// utils.go::getColumns
@@ -96,14 +74,11 @@ func (s *PostgresSuite) TestCompileCreate() {
9674
// postgres.go::TypeString
9775
mockColumn2.EXPECT().GetLength().Return(100).Once()
9876
// postgres.go::ModifyDefault
99-
mockColumn2.EXPECT().GetChange().Return(false).Once()
10077
mockColumn2.EXPECT().GetDefault().Return(nil).Once()
10178
// postgres.go::ModifyIncrement
102-
mockColumn2.EXPECT().GetChange().Return(false).Once()
10379
mockBlueprint.EXPECT().HasCommand("primary").Return(false).Once()
10480
mockColumn2.EXPECT().GetType().Return("string").Once()
10581
// postgres.go::ModifyNullable
106-
mockColumn2.EXPECT().GetChange().Return(false).Once()
10782
mockColumn2.EXPECT().GetNullable().Return(true).Once()
10883

10984
s.Equal("create table users (id serial primary key not null,name varchar(100) null)",
@@ -145,42 +120,15 @@ func (s *PostgresSuite) TestModifyDefault() {
145120
setup func()
146121
expectSql string
147122
}{
148-
{
149-
name: "with change and AutoIncrement",
150-
setup: func() {
151-
mockColumn.EXPECT().GetChange().Return(true).Once()
152-
mockColumn.EXPECT().GetAutoIncrement().Return(true).Once()
153-
},
154-
},
155-
{
156-
name: "with change and not AutoIncrement, default is nil",
157-
setup: func() {
158-
mockColumn.EXPECT().GetChange().Return(true).Once()
159-
mockColumn.EXPECT().GetAutoIncrement().Return(false).Once()
160-
mockColumn.EXPECT().GetDefault().Return(nil).Once()
161-
},
162-
expectSql: "drop default",
163-
},
164-
{
165-
name: "with change and not AutoIncrement, default is not nil",
166-
setup: func() {
167-
mockColumn.EXPECT().GetChange().Return(true).Once()
168-
mockColumn.EXPECT().GetAutoIncrement().Return(false).Once()
169-
mockColumn.EXPECT().GetDefault().Return("goravel").Twice()
170-
},
171-
expectSql: "set default 'goravel'",
172-
},
173123
{
174124
name: "without change and default is nil",
175125
setup: func() {
176-
mockColumn.EXPECT().GetChange().Return(false).Once()
177126
mockColumn.EXPECT().GetDefault().Return(nil).Once()
178127
},
179128
},
180129
{
181130
name: "without change and default is not nil",
182131
setup: func() {
183-
mockColumn.EXPECT().GetChange().Return(false).Once()
184132
mockColumn.EXPECT().GetDefault().Return("goravel").Twice()
185133
},
186134
expectSql: " default 'goravel'",
@@ -205,22 +153,11 @@ func (s *PostgresSuite) TestModifyNullable() {
205153
mockBlueprint := mocksschema.NewBlueprint(s.T())
206154

207155
mockColumn := mocksschema.NewColumnDefinition(s.T())
208-
mockColumn.EXPECT().GetChange().Return(true).Once()
209-
mockColumn.EXPECT().GetNullable().Return(true).Once()
210-
211-
s.Equal("drop not null", s.grammar.ModifyNullable(mockBlueprint, mockColumn))
212-
213-
mockColumn.EXPECT().GetChange().Return(true).Once()
214-
mockColumn.EXPECT().GetNullable().Return(false).Once()
215-
216-
s.Equal("set not null", s.grammar.ModifyNullable(mockBlueprint, mockColumn))
217156

218-
mockColumn.EXPECT().GetChange().Return(false).Once()
219157
mockColumn.EXPECT().GetNullable().Return(true).Once()
220158

221159
s.Equal(" null", s.grammar.ModifyNullable(mockBlueprint, mockColumn))
222160

223-
mockColumn.EXPECT().GetChange().Return(false).Once()
224161
mockColumn.EXPECT().GetNullable().Return(false).Once()
225162

226163
s.Equal(" not null", s.grammar.ModifyNullable(mockBlueprint, mockColumn))
@@ -230,11 +167,6 @@ func (s *PostgresSuite) TestModifyIncrement() {
230167
mockBlueprint := mocksschema.NewBlueprint(s.T())
231168

232169
mockColumn := mocksschema.NewColumnDefinition(s.T())
233-
mockColumn.EXPECT().GetChange().Return(true).Once()
234-
235-
s.Empty(s.grammar.ModifyIncrement(mockBlueprint, mockColumn))
236-
237-
mockColumn.EXPECT().GetChange().Return(false).Once()
238170
mockBlueprint.EXPECT().HasCommand("primary").Return(false).Once()
239171
mockColumn.EXPECT().GetType().Return("bigInteger").Once()
240172
mockColumn.EXPECT().GetAutoIncrement().Return(true).Once()

0 commit comments

Comments
 (0)