Migration

Topics: Writing modules
Mar 21, 2011 at 4:12 PM

Hello, it's me again.

I tried to migrate table to version 2 - add a field, and alter table names (typos). Tried this

   SchemaBuilder.AlterTable("QRCodePartRecord", table => table
               .AlterColumn("qrcodeErrorCorrect", col => col.ColumnName = "qrCodeErrorCorrect")

- would not work, what is the syntax to change column name?

Or I should simply delete table and recreate? 

I am at learning stage, so would like to do it 'the right way' for later.

Heres my migration.cs

namespace QRCode {
    public class Migrations : DataMigrationImpl {

        public int Create() {
			// Creating table QRCodePartRecord
			SchemaBuilder.CreateTable("QRCodePartRecord", table => table
				.ContentPartRecord()
				.Column("qrcodeErrorCorrect", DbType.String)
				.Column("qrcodeEncodeMode", DbType.String)
				.Column("qrcodeVersion", DbType.Int32)
				.Column("qrCodeBackgroundColor", DbType.String)
				.Column("qrCodeForegroundColor", DbType.String)
				.Column("qrCodeScale", DbType.Int32)
			);
            ContentDefinitionManager.AlterPartDefinition(
                typeof(QRCodePart).Name, cfg => cfg.Attachable());


            return 1;
        }
        public int UpdateFrom1()
        {
            SchemaBuilder.AlterTable("QRCodePartRecord", table => table
                .AddColumn("qrCodeShow", DbType.Boolean)
           );
            SchemaBuilder.AlterTable("QRCodePartRecord", table => table
               .AlterColumn("qrcodeErrorCorrect", col => col.ColumnName = "qrCodeErrorCorrect")
          );
            SchemaBuilder.AlterTable("QRCodePartRecord", table => table
             .AlterColumn("qrcodeEncodeMode", col => col.ColumnName = "qrCodeEncodeMode")
);
            SchemaBuilder.AlterTable("QRCodePartRecord", table => table
            .AlterColumn("qrcodeVersion", col => col.ColumnName = "qrCodeVersion")
);
            return 2;
        }

Coordinator
Mar 21, 2011 at 5:00 PM

I'm not sure that you can. restarting may be your simplest option.

Mar 21, 2011 at 10:52 PM

I don't have the source at home (not so bad ass geek huh?) but i would search for the words "RENAME COLUMN" as a part in "ALTER TABLE {0} RENAME COLUMN {1} to {2}" 

Else start an issue for the SchemaBuilder 

Mar 22, 2011 at 1:22 PM
Edited Mar 22, 2011 at 1:25 PM

Looking at the Orchard.Framework.Data.Migration classes i don't see a RenameColumnCommand. In the DefaultDataMigrationInterpreter class there isn't any support for renaming a column. I'll file in a issue, since we all make mistakes with column names...

A workaround adding a new column, copying data and dropping the old column would be possible but support from the SchemaBuilder is nicer.

Issue created, go ahead and vote http://orchard.codeplex.com/workitem/17525