@@ -57,22 +57,22 @@ type Migrator struct {
5757 migrator.Migrator
5858}
5959
60- // RunWithValue run migration with statement value
60+ // RunWithValue runs migration for the given ` value`
6161func (m Migrator ) RunWithValue (value interface {}, fc func (* gorm.Statement ) error ) error {
6262 if table , ok := value .(string ); ok {
6363 return m .Migrator .RunWithValue (table , fc )
6464 }
6565 return m .Migrator .RunWithValue (value , fc )
6666}
6767
68- // Database
68+ // CurrentDatabase returns the the name of the current Oracle database
6969func (m Migrator ) CurrentDatabase () string {
7070 var name string
7171 m .DB .Raw ("SELECT ora_database_name FROM dual" ).Scan (& name )
7272 return name
7373}
7474
75- // CreateTable create table in database for values
75+ // CreateTable creates table in database for the given ` values`
7676func (m Migrator ) CreateTable (values ... interface {}) error {
7777
7878 for _ , value := range m .ReorderModels (values , false ) {
@@ -201,7 +201,9 @@ func (m Migrator) CreateTable(values ...interface{}) error {
201201 return nil
202202}
203203
204- // Drops the table starting from the bottom of the dependency chain
204+ // DropTable drops the table starting from the bottom of the dependency chain.
205+ // The function returns an error when Oracle databases report a missing table.
206+ // If multiple errors occur, it returns a combined (joint) error.
205207func (m Migrator ) DropTable (values ... interface {}) error {
206208 var errorList []error
207209 values = m .ReorderModels (values , false )
@@ -234,7 +236,7 @@ func (m Migrator) HasTable(value interface{}) bool {
234236 return count > 0
235237}
236238
237- // RenameTable rename table from oldName to newName
239+ // RenameTable renames table from oldName to newName
238240func (m Migrator ) RenameTable (oldName , newName interface {}) error {
239241 var oldTable , newTable interface {}
240242 if v , ok := oldName .(string ); ok {
@@ -259,10 +261,6 @@ func (m Migrator) RenameTable(oldName, newName interface{}) error {
259261 }
260262 }
261263
262- // TODO: Cannot rename a table that is referenced by a foreign key
263- // Disable the constraints for each referencing table before renaming,
264- // and recreate them after renaming
265-
266264 return m .DB .Exec ("RENAME ? TO ?" , oldTable , newTable ).Error
267265}
268266
@@ -273,8 +271,7 @@ func (m Migrator) GetTables() (tableList []string, err error) {
273271 return
274272}
275273
276- // Columns
277- // AddColumn create `name` column for value
274+ // AddColumn creates `name` column for the given `value`
278275func (m Migrator ) AddColumn (value interface {}, name string ) error {
279276 return m .RunWithValue (value , func (stmt * gorm.Statement ) error {
280277 // Check if the column name is already used
@@ -290,7 +287,7 @@ func (m Migrator) AddColumn(value interface{}, name string) error {
290287 })
291288}
292289
293- // DropColumn drop value's `name` column
290+ // DropColumn drops value's `name` column
294291func (m Migrator ) DropColumn (value interface {}, name string ) error {
295292 return m .RunWithValue (value , func (stmt * gorm.Statement ) error {
296293 if stmt .Schema != nil {
@@ -307,7 +304,7 @@ func (m Migrator) DropColumn(value interface{}, name string) error {
307304 })
308305}
309306
310- // AlterColumn alter value's `field` column's type based on schema definition
307+ // AlterColumn alters value's `field` column's type based on schema definition
311308func (m Migrator ) AlterColumn (value interface {}, field string ) error {
312309 return m .RunWithValue (value , func (stmt * gorm.Statement ) error {
313310 if stmt .Schema != nil {
@@ -326,7 +323,7 @@ func (m Migrator) AlterColumn(value interface{}, field string) error {
326323 })
327324}
328325
329- // HasColumn check has column `field` for value or not
326+ // HasColumn checks whether the table for the given value contains the specified column `field`
330327func (m Migrator ) HasColumn (value interface {}, field string ) bool {
331328 var count int64
332329
@@ -340,7 +337,7 @@ func (m Migrator) HasColumn(value interface{}, field string) bool {
340337 return count > 0
341338}
342339
343- // ColumnTypes return columnTypes []gorm.ColumnType and execErr error
340+ // ColumnTypes returns the column types for the given value’s table and any error encountered during execution
344341func (m Migrator ) ColumnTypes (value interface {}) ([]gorm.ColumnType , error ) {
345342 columnTypes := make ([]gorm.ColumnType , 0 )
346343 execErr := m .RunWithValue (value , func (stmt * gorm.Statement ) (err error ) {
@@ -370,7 +367,7 @@ func (m Migrator) ColumnTypes(value interface{}) ([]gorm.ColumnType, error) {
370367 return columnTypes , execErr
371368}
372369
373- // HasConstraint check has constraint or not
370+ // HasConstraint checks whether the table for the given `value` contains the specified constraint `name`
374371func (m Migrator ) HasConstraint (value interface {}, name string ) bool {
375372 var count int64
376373
@@ -389,8 +386,7 @@ func (m Migrator) HasConstraint(value interface{}, name string) bool {
389386 return count > 0
390387}
391388
392- // Indexes
393- // DropIndex drop index `name`
389+ // DropIndex drops the index with the specified `name` from the table associated with `value`
394390func (m Migrator ) DropIndex (value interface {}, name string ) error {
395391 return m .RunWithValue (value , func (stmt * gorm.Statement ) error {
396392 if stmt .Schema != nil {
@@ -403,7 +399,7 @@ func (m Migrator) DropIndex(value interface{}, name string) error {
403399 })
404400}
405401
406- // HasIndex check has index `name` or not
402+ // HasIndex checks whether the table for the given `value` contains an index with the specified `name`
407403func (m Migrator ) HasIndex (value interface {}, name string ) bool {
408404 var count int64
409405 m .RunWithValue (value , func (stmt * gorm.Statement ) error {
@@ -423,7 +419,7 @@ func (m Migrator) HasIndex(value interface{}, name string) bool {
423419 return count > 0
424420}
425421
426- // RenameIndex rename index from oldName to newName
422+ // RenameIndex renames index from oldName to newName on the table for the given `value`
427423func (m Migrator ) RenameIndex (value interface {}, oldName , newName string ) error {
428424 return m .RunWithValue (value , func (stmt * gorm.Statement ) error {
429425 return m .DB .Exec (
@@ -460,7 +456,7 @@ func (m Migrator) FullDataTypeOf(field *schema.Field) (expr clause.Expr) {
460456 return expr
461457}
462458
463- // Build Oracle-compatible default values from string
459+ // Builds Oracle-compatible default values from string
464460func (m Migrator ) buildOracleDefault (defaultValue string ) string {
465461 defaultValue = strings .TrimSpace (defaultValue )
466462
0 commit comments