{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13651","repository_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore","labels_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13651/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13651/comments","events_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13651/events","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/13651","id":370866207,"node_id":"MDU6SXNzdWUzNzA4NjYyMDc=","number":13651,"title":"Column Created Time in EFMigrationsHistory","user":{"login":"denis-pujdak-adm-it","id":13495631,"node_id":"MDQ6VXNlcjEzNDk1NjMx","avatar_url":"https://avatars3.githubusercontent.com/u/13495631?v=4","gravatar_id":"","url":"https://api.github.com/users/denis-pujdak-adm-it","html_url":"https://github.com/denis-pujdak-adm-it","followers_url":"https://api.github.com/users/denis-pujdak-adm-it/followers","following_url":"https://api.github.com/users/denis-pujdak-adm-it/following{/other_user}","gists_url":"https://api.github.com/users/denis-pujdak-adm-it/gists{/gist_id}","starred_url":"https://api.github.com/users/denis-pujdak-adm-it/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/denis-pujdak-adm-it/subscriptions","organizations_url":"https://api.github.com/users/denis-pujdak-adm-it/orgs","repos_url":"https://api.github.com/users/denis-pujdak-adm-it/repos","events_url":"https://api.github.com/users/denis-pujdak-adm-it/events{/privacy}","received_events_url":"https://api.github.com/users/denis-pujdak-adm-it/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-10-17T01:55:28Z","updated_at":"2018-10-17T19:38:57Z","closed_at":null,"author_association":"NONE","body":"Can I add a column `Time` to the table `__EFMigrationsHistory` with a utc time of the created row populated.\r\nAs I can see at the moment there is a hard-coded `HistoryRow` which cannot be changed outside.\r\n\r\nAny ideas are very welcome.\r\n\r\nSee the following example\r\n```C#\r\npublic class CustomHistoryRepository : NpgsqlHistoryRepository\r\n    {\r\n        public CustomHistoryRepository(HistoryRepositoryDependencies dependencies)\r\n            : base(dependencies)\r\n        {\r\n        }\r\n\r\n        protected override void ConfigureTable(EntityTypeBuilder<HistoryRow> history)\r\n        {\r\n            base.ConfigureTable(history);\r\n\r\n            history\r\n                .Property<DateTime>(\"Time\")\r\n                .HasValueGenerator<DateTimeUtcValueGenerator>()\r\n                .ValueGeneratedOnAdd();\r\n        }\r\n\r\n        public override string GetInsertScript(HistoryRow row)\r\n        {\r\n            return base.GetInsertScript(row);\r\n        }\r\n    }\r\n```\r\n\r\n```C#\r\nvar dbOptions = new DbContextOptionsBuilder(options)\r\n                    .UseNpgsql(settings.DefaultConnection)\r\n                    .ReplaceService<IHistoryRepository, CustomHistoryRepository>()\r\n                    .Options;\r\n```\r\n\r\n### Further technical details\r\nEF Core version: Microsoft.AspNetCore.Identity.EntityFrameworkCore v.2.1.3\r\nDatabase Provider: Npgsql.EntityFrameworkCore.PostgreSQL v.2.1.2\r\nOperating system: Visual Studio 2017 Community v.15.8.7"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/comments/430761063","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/13651#issuecomment-430761063","issue_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13651","id":430761063,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMDc2MTA2Mw==","user":{"login":"bricelam","id":1226749,"node_id":"MDQ6VXNlcjEyMjY3NDk=","avatar_url":"https://avatars2.githubusercontent.com/u/1226749?v=4","gravatar_id":"","url":"https://api.github.com/users/bricelam","html_url":"https://github.com/bricelam","followers_url":"https://api.github.com/users/bricelam/followers","following_url":"https://api.github.com/users/bricelam/following{/other_user}","gists_url":"https://api.github.com/users/bricelam/gists{/gist_id}","starred_url":"https://api.github.com/users/bricelam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bricelam/subscriptions","organizations_url":"https://api.github.com/users/bricelam/orgs","repos_url":"https://api.github.com/users/bricelam/repos","events_url":"https://api.github.com/users/bricelam/events{/privacy}","received_events_url":"https://api.github.com/users/bricelam/received_events","type":"User","site_admin":false},"created_at":"2018-10-17T19:38:57Z","updated_at":"2018-10-17T19:38:57Z","author_association":"MEMBER","body":"The entity type is only used for generating the `CREATE TABLE` statement. All other configuration is ignored.\r\n\r\nYou could generate the value in the database using a default value:\r\n\r\n``` csharp\r\nhistory\r\n    .Property<DateTime>(\"Time\")\r\n    .HasDefaultValueSql(\"CURRENT_TIMESTAMP AT TIME ZONE 'UTC'\");\r\n```\r\n\r\nOr you could manually change the INSERT statement. Note however, that this would do funny things when generating a SQL script form the migrations. The value would be the time you generated the script, not the time you actually applied the migration.\r\n\r\n``` csharp\r\npublic override string GetInsertScript(HistoryRow row)\r\n{\r\n    var stringMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string));\r\n    var dateTimeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string));\r\n\r\n    return @\"INSERT INTO \")\r\n        .Append(SqlGenerationHelper.DelimitIdentifier(TableName, TableSchema))\r\n        .Append(\" (\")\r\n        .Append(SqlGenerationHelper.DelimitIdentifier(MigrationIdColumnName))\r\n        .Append(\", \")\r\n        .Append(SqlGenerationHelper.DelimitIdentifier(ProductVersionColumnName))\r\n        .Append(\", \")\r\n        .Append(SqlGenerationHelper.DelimitIdentifier(\"Time\"))\r\n        .AppendLine(\")\")\r\n        .Append(\"VALUES (\")\r\n        .Append(stringTypeMapping.GenerateSqlLiteral(row.MigrationId))\r\n        .Append(\", \")\r\n        .Append(stringTypeMapping.GenerateSqlLiteral(row.ProductVersion))\r\n        .Append(\", \")\r\n        .Append(dateTimeMapping.GenerateSqlLiteral(DateTime.UtcNow))\r\n        .Append(\")\")\r\n        .AppendLine(SqlGenerationHelper.StatementTerminator)\r\n        .ToString();\r\n}\r\n``` "}}
{"actor":{"display_login":"bricelam"}}