fluentmigrator / documentation

This is the source of fluentmigrator.github.io
https://fluentmigrator.github.io
Creative Commons Attribution Share Alike 4.0 International
6 stars 18 forks source link

MyCustomMigrationAttribute example #68

Closed mgroves closed 1 year ago

mgroves commented 1 year ago

For the example in this page: https://fluentmigrator.github.io/articles/migration/migration-attribute-custom.html?q=enforce there is an Author member:

/// <summary>
/// Mark all migrations with this INSTEAD of [Migration].
/// </summary>
public class MyCustomMigrationAttribute : FluentMigrator.MigrationAttribute
{
    public MyCustomMigrationAttribute(int branchNumber, int year, int month, int day, int hour, int minute, string author)
       : base(CalculateValue(branchNumber, year, month, day, hour, minute))
   {
       this.Author = author;
   }
   public string Author { get; private set; }
   private static long CalculateValue(int branchNumber, int year, int month, int day, int hour, int minute)
   {
      return branchNumber * 1000000000000L + year * 100000000L + month * 1000000L + day * 10000L + hour * 100L + minute;
   }
}

But it doesn't seem to be used for anything other than just having an author listed in the source code.

But wouldn't that be adequately accomplished with source control? Why is Author used in this example?

Maybe that can be addressed/further explained in the text of this page of documentation?

jzabroski commented 1 year ago

I would assume the reason is to put convention around the default of choosing a string to identify a description for the migration. If the description of the migration is like the title of an article in the magazine, author is... the author.

That being said, this is a fictitious example and I personally don't customize MigrationAttribute, and I've written thousands of migrations across many different types of projects. They all have the same basic architecture. But others might want something differently. I recall one person wanted a Team Name to split migrations by. I didn't think that was a great idea, but I gave my thoughts, and if the people using the framework can find a workflow with that approach that works flawlessly, then it is great for them.

mgroves commented 1 year ago

I see. So this could also be done with, say, a code comment?

jzabroski commented 1 year ago

It's just for demonstrating what could be done. I'm trying to draw a distinction of, would you ask Microsoft why they picked a particular example discussing how to use attributes in general? https://learn.microsoft.com/en-us/dotnet/csharp/advanced-topics/reflection-and-attributes/attribute-tutorial uses Foo for a class name.

Just trying to understand what you want to achieve. If it's to settle a discussion with a coworker who copy pasted this code verbatim, then you don't need me to tell this person should "do his own homework".

I personally didn't write this example but I think for setting the version, many people use the non Author part.

If you think it should be changed, submit a pr.

jzabroski commented 1 year ago

Maybe what you really want to know is, how can Author be made use of outside this class? That would require customizing how the VersionInfo data is stored so that a new attribute can be tracked. Is that what you're really trying to get at?

mgroves commented 1 year ago

Not trying to get at anything, other than I showed this example to a user group, someone asked me why Author was there, and it wasn't used to create the version number, so I didn't know.

jzabroski commented 1 year ago

Ah, sorry about that. I think we can add a note about populating VersionInfo table with more columns. For most people, that's overkill, including myself.

jzabroski commented 1 year ago

Added. Thanks for the good discussion.