Package liquibase.change.core

Examples of liquibase.change.core.CreateTableChange


        super(SQLFileChange.class);
    }

    @Override
    public Change[] prepareDatabase(SQLFileChange change) throws Exception {
        CreateTableChange createTableChange = new CreateTableChange();
        createTableChange.setTableName("person");
        createTableChange.addColumn(new ColumnConfig().setName("id").setType("int").setConstraints(new ConstraintsConfig().setNullable(false).setPrimaryKey(true)));
        createTableChange.addColumn(new ColumnConfig().setName("not_id").setType("int"));

        return new Change[] {createTableChange };
    }
View Full Code Here


        super(UpdateDataChange.class);
    }

    @Override
    public Change[]  prepareDatabase(UpdateDataChange change) throws Exception {
        CreateTableChange createTableChange = new CreateTableChange();
        createTableChange.setCatalogName(change.getCatalogName());
        createTableChange.setSchemaName(change.getSchemaName());
        createTableChange.setTableName(change.getTableName());

        for (ColumnConfig column : change.getColumns()) {
            createTableChange.addColumn(new ColumnConfig().setName(column.getName()).setType("int"));
        }
        createTableChange.addColumn(new ColumnConfig().setName("other_column").setType("int"));

        if (change.getWhere() != null) {
            String whereColumn = change.getWhere().replaceFirst("(.*?)=.*", "$1");
            createTableChange.addColumn(new ColumnConfig().setName(whereColumn).setType("varchar(50)"));
        }

        return new Change[] {createTableChange };
    }
View Full Code Here

        super(AddAutoIncrementChange.class);
    }

    @Override
    public Change[] prepareDatabase(AddAutoIncrementChange change) throws DatabaseException {
        CreateTableChange createTable = new CreateTableChange();
        createTable.setCatalogName(change.getCatalogName());
        createTable.setSchemaName(change.getSchemaName());
        createTable.setTableName(change.getTableName());
        String dataType = change.getColumnDataType();
        if (dataType == null) {
            dataType = "int";
        }
        createTable.addColumn(new ColumnConfig().setName(change.getColumnName()).setType(dataType).setConstraints(new ConstraintsConfig().setPrimaryKey(true).setNullable(false)));

        return new Change[] {createTable};
    }
View Full Code Here

        super(AddDefaultValueChange.class);
    }

    @Override
    public Change[] prepareDatabase(AddDefaultValueChange change) throws Exception {
        CreateTableChange createTableChange = new CreateTableChange();
        createTableChange.setCatalogName(change.getCatalogName());
        createTableChange.setSchemaName(change.getSchemaName());
        createTableChange.setTableName(change.getTableName());
        createTableChange.addColumn(new ColumnConfig().setName("other_col").setType("int"));

        String type = change.getColumnDataType();
        if (type == null) {
            if (change.getDefaultValueDate() != null) {
                type = "datetime";
            } else if (change.getDefaultValueBoolean() != null) {
                type = "boolean";
            } else if (change.getDefaultValueNumeric() != null) {
                type = "decimal";
            } else {
                type = "varchar(255)";
            }
        }
        createTableChange.addColumn(new ColumnConfig().setName(change.getColumnName()).setType(type));

        return new Change[]{createTableChange};
    }
View Full Code Here

        super(DropDefaultValueChange.class);
    }

    @Override
    public Change[]  prepareDatabase(DropDefaultValueChange change) throws Exception {
        CreateTableChange createTableChange = new CreateTableChange();
        createTableChange.setCatalogName(change.getCatalogName());
        createTableChange.setSchemaName(change.getSchemaName());
        createTableChange.setTableName(change.getTableName());
        createTableChange.addColumn(new ColumnConfig().setName("other_col").setType("int"));
        String dataType = change.getColumnDataType();
        if (dataType == null) {
            dataType = "int";
        }
        createTableChange.addColumn(new ColumnConfig().setName(change.getColumnName()).setType(dataType).setDefaultValue("1"));

        return new Change[] {createTableChange };

    }
View Full Code Here

        super(AddForeignKeyConstraintChange.class);
    }

    @Override
    public Change[]  prepareDatabase(AddForeignKeyConstraintChange change) throws DatabaseException {
        CreateTableChange createBaseTable = new CreateTableChange();
        createBaseTable.setCatalogName(change.getBaseTableCatalogName());
        createBaseTable.setSchemaName(change.getBaseTableSchemaName());
        createBaseTable.setTableName(change.getBaseTableName());
        for (String columnName : change.getBaseColumnNames().split("\\s+,\\s+")) {
            createBaseTable.addColumn(new ColumnConfig().setName(columnName).setType("int"));
        }

        CreateTableChange createReferencedTable= new CreateTableChange();
        createReferencedTable.setCatalogName(change.getReferencedTableCatalogName());
        createReferencedTable.setSchemaName(change.getReferencedTableSchemaName());
        createReferencedTable.setTableName(change.getReferencedTableName());
        for (String columnName : change.getReferencedColumnNames().split("\\s+,\\s+")) {
            createReferencedTable.addColumn(new ColumnConfig().setName(columnName).setType("int").setConstraints(new ConstraintsConfig().setPrimaryKey(true)));
        }

        return new Change[] {createBaseTable, createReferencedTable };
    }
View Full Code Here

        super(RenameColumnChange.class);
    }

    @Override
    public Change[]  prepareDatabase(RenameColumnChange change) throws Exception {
        CreateTableChange createTableChange = new CreateTableChange();
        createTableChange.setCatalogName(change.getCatalogName());
        createTableChange.setSchemaName(change.getSchemaName());
        createTableChange.setTableName(change.getTableName());
        createTableChange.addColumn(new ColumnConfig().setName("other_column").setType("int"));
        String dataType = change.getColumnDataType();
        if (dataType == null) {
            dataType = "int";
        }
        createTableChange.addColumn(new ColumnConfig().setName(change.getOldColumnName()).setType(dataType));

        return new Change[] {createTableChange };
    }
View Full Code Here

        super(RenameTableChange.class);
    }

    @Override
    public Change[]  prepareDatabase(RenameTableChange change) throws Exception {
        CreateTableChange createTableChange = new CreateTableChange();
        createTableChange.setCatalogName(change.getCatalogName());
        createTableChange.setSchemaName(change.getSchemaName());
        createTableChange.setTableName(change.getOldTableName());
        createTableChange.addColumn(new ColumnConfig().setName("id").setType("int"));
        createTableChange.addColumn(new ColumnConfig().setName("other_column").setType("varchar(10)"));

        return new Change[] {createTableChange };
    }
View Full Code Here

        if (usedTableName == null) {
            usedTableName = "person";
        }

        CreateTableChange createTableChange = new CreateTableChange();
        createTableChange.setCatalogName(change.getCatalogName());
        createTableChange.setSchemaName(change.getSchemaName());
        createTableChange.setTableName(usedTableName);

        createTableChange.addColumn(new ColumnConfig().setName("name").setType("varchar(255)").setConstraints(new ConstraintsConfig().setNullable(false)));
        createTableChange.addColumn(new ColumnConfig().setName("other_column").setType("int"));

        CreateIndexChange createIndexChange = new CreateIndexChange();
        createIndexChange.setIndexName(change.getIndexName());
        createIndexChange.setTableName(usedTableName);
        createIndexChange.addColumn((AddColumnConfig) new AddColumnConfig().setName("name"));
View Full Code Here

    }


    @Test
    public void visit_successful() throws Exception {
        CreateTableChange change1 = new CreateTableChange();
        change1.setTableName("table1");
        ColumnConfig column1 = new ColumnConfig();
        change1.addColumn(column1);
        column1.setName("col1");
        column1.setType("int");

        CreateTableChange change2 = new CreateTableChange();
        change2.setTableName("table2");
        ColumnConfig column2 = new ColumnConfig();
        change2.addColumn(column2);
        column2.setName("col2");
        column2.setType("int");

        changeSet1.addChange(change1);
        changeSet2.addChange(change2);
View Full Code Here

TOP

Related Classes of liquibase.change.core.CreateTableChange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.