LinuxDoku / migratordotnet

Automatically exported from code.google.com/p/migratordotnet
0 stars 0 forks source link

Enhancement - locking down the version number a bit more #149

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
So far, I'm loving Migrator.   But one of the things that I'm absolutely
terrified of, is messing up the migration number, and not seeing the
mistake until the database is totally fried (I was the victim of
schema-change disaster before Migrator <shudder>).  For example forgetting
the redundant zero in the month: 20100423 vs 2010423.  

So being the lazy programmer that I am, I simply added a new constructor:

public MigrationAttribute(Int16 year, byte month, byte day, byte step)
{
    checked
    {
        Version = year + month + day + step;
    }
}

I think this small addition could keep a lot of other lazy programmers like
me from making that mistake.

Original issue reported on code.google.com by hired.m...@gmail.com on 23 Apr 2010 at 6:24

GoogleCodeExporter commented 8 years ago
Nevermind, don't use the above constructor, I didn't think it through very 
well. 
(I'm a lazy programmer after all)  Here is a better one:

        public MigrationAttribute(Int16 year, byte month, byte day, byte step)
        {
            if (day > 31)
                throw new ArgumentOutOfRangeException("day");
            if (month > 12)
                throw new ArgumentOutOfRangeException("month");
            if (year > 4096)
                throw new ArgumentOutOfRangeException("year");

            checked
            {
                //    |   year    ||mnt||day| | step |
                // 00000000 00000000 00000000 00000000
                Version = year << 17 + (month << 13) + (day << 8) + step;
            }
        }

Original comment by hired.m...@gmail.com on 28 Apr 2010 at 4:07

GoogleCodeExporter commented 8 years ago
It would be better to use the built in DateTime or Calendar objects to validate 
the
time stamp.  Also, different projects may want slightly different standards on
version numbers so it could make sense to provide different overloads.  I would
consider including:
1) date, hour, minute
2) date, hour, minute, second
3) date, step (as hired.mind shows)

Original comment by WalkerCo...@gmail.com on 24 May 2010 at 8:33

GoogleCodeExporter commented 8 years ago
Yeah I would love to have used a DateTime object but unfortunately it's not 
possible
due to the nature of Attributes.   Attribute arguments must be a constant type. 

Original comment by hired.m...@gmail.com on 26 May 2010 at 8:27