(ddls []DDL, mode GeneratorMode, defaultSchema string, legacyIgnoreQuotes bool, mysqlLowerCaseTableNames int)
| 3833 | } |
| 3834 | |
| 3835 | func aggregateDDLsToSchema(ddls []DDL, mode GeneratorMode, defaultSchema string, legacyIgnoreQuotes bool, mysqlLowerCaseTableNames int) (*AggregatedSchema, error) { |
| 3836 | aggregated := &AggregatedSchema{ |
| 3837 | Tables: []*Table{}, |
| 3838 | PartitionOfs: []*CreatePartitionOf{}, |
| 3839 | Views: []*View{}, |
| 3840 | Triggers: []*Trigger{}, |
| 3841 | Events: []*Event{}, |
| 3842 | Types: []*Type{}, |
| 3843 | Domains: []*Domain{}, |
| 3844 | Comments: []*Comment{}, |
| 3845 | Extensions: []*Extension{}, |
| 3846 | Schemas: []*Schema{}, |
| 3847 | Privileges: []*GrantPrivilege{}, |
| 3848 | } |
| 3849 | |
| 3850 | for _, ddl := range ddls { |
| 3851 | switch stmt := ddl.(type) { |
| 3852 | case *CreateTable: |
| 3853 | table := stmt.table // copy table |
| 3854 | aggregated.Tables = append(aggregated.Tables, &table) |
| 3855 | case *CreatePartitionOf: |
| 3856 | // Copy the partition of statement |
| 3857 | partitionOf := *stmt |
| 3858 | aggregated.PartitionOfs = append(aggregated.PartitionOfs, &partitionOf) |
| 3859 | case *CreateIndex: |
| 3860 | table := findTableQuoteAware(aggregated.Tables, stmt.tableName, defaultSchema, mode, legacyIgnoreQuotes, mysqlLowerCaseTableNames) |
| 3861 | if table == nil { |
| 3862 | view := findViewQuoteAware(aggregated.Views, stmt.tableName, defaultSchema, mode, legacyIgnoreQuotes, mysqlLowerCaseTableNames) |
| 3863 | if view == nil { |
| 3864 | return nil, fmt.Errorf("CREATE INDEX is performed before CREATE TABLE: %s", ddl.Statement()) |
| 3865 | } |
| 3866 | // TODO: check duplicated creation |
| 3867 | view.indexes = append(view.indexes, stmt.index) |
| 3868 | } else { |
| 3869 | // TODO: check duplicated creation |
| 3870 | table.indexes = append(table.indexes, stmt.index) |
| 3871 | } |
| 3872 | case *AddIndex: |
| 3873 | table := findTableQuoteAware(aggregated.Tables, stmt.tableName, defaultSchema, mode, legacyIgnoreQuotes, mysqlLowerCaseTableNames) |
| 3874 | if table == nil { |
| 3875 | return nil, fmt.Errorf("ADD INDEX is performed before CREATE TABLE: %s", ddl.Statement()) |
| 3876 | } |
| 3877 | // TODO: check duplicated creation |
| 3878 | table.indexes = append(table.indexes, stmt.index) |
| 3879 | case *AddPrimaryKey: |
| 3880 | table := findTableQuoteAware(aggregated.Tables, stmt.tableName, defaultSchema, mode, legacyIgnoreQuotes, mysqlLowerCaseTableNames) |
| 3881 | if table == nil { |
| 3882 | return nil, fmt.Errorf("ADD PRIMARY KEY is performed before CREATE TABLE: %s", ddl.Statement()) |
| 3883 | } |
| 3884 | |
| 3885 | newColumns := map[string]*Column{} |
| 3886 | for _, column := range table.columns { |
| 3887 | if column.name.Name == stmt.index.columns[0].ColumnName() { // TODO: multi-column primary key? |
| 3888 | column.keyOption = ColumnKeyPrimary |
| 3889 | } |
| 3890 | newColumns[column.name.Name] = column |
| 3891 | } |
| 3892 | table.columns = newColumns |
no test coverage detected