GithubHelp home page GithubHelp logo

fluentmigrator's Introduction

fluentmigrator's People

Contributors

cbilson avatar jetheredge avatar ngbrown avatar paulbatum avatar rauhryan avatar rebootd avatar schambers avatar stevehodgkiss avatar swalters avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fluentmigrator's Issues

Alter column

It would be nice if there was a way to alter an existing column without deleting and recreating it, for example when you want to change a data type or default value but retain all the data. Maybe something like:

Alter.Column("foo").OnTable("bar").AsInt16().WithDefaultValue(0);

Deleting a column with a default value throws an error in SQL Server

Deleting a column with a default value throws an error in SQL Server, since SQL Server creates a default constraint to enforce the default value. If you are dropping a column, you don't need the default value constrain anymore either, so it should be safe to delete. Here's some code to do it (replace line 71 of SqlServerGenerator.cs with this, if it isn't horribly mangled by the editor):

public override string Generate(DeleteColumnExpression expression)
{
// before we drop a column, we have to drop any default value constraints in SQL Server
string sql = @"
DECLARE @default sysname, @Sql nvarchar(max);

    -- get name of default constraint
    SELECT @default = name 
    FROM sys.default_constraints 
    WHERE parent_object_id = object_id('{0}')
    AND type = 'D'
    AND parent_column_id = (
        SELECT column_id 
        FROM sys.columns 
        WHERE object_id = object_id('{0}')
        AND name = '{1}'
    );

    -- create alter table command as string and run it
    SET @sql = N'ALTER TABLE [{0}] DROP CONSTRAINT ' + @default;
    EXEC sp_executesql @sql;

    -- now we can finally drop column
    ALTER TABLE [{0}] DROP COLUMN [{1}];";

return FormatExpression(sql, expression.TableName, expression.ColumnName);

}

Raw SQL Expression

It may be worthwhile to create an Expressoin that can execute raw sql. Would need to add a new RawExpression and then add it to the ProcessorBase class so that the visitor can traverse it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.