{"action":"created","comment":{"url":"https://api.github.com/repos/rapidcore/rapidcore/pulls/comments/171875554","pull_request_review_id":100809179,"id":171875554,"diff_hunk":"@@ -0,0 +1,115 @@\n+﻿using System;\n+using System.Collections.Generic;\n+using System.Data;\n+using System.Text;\n+using System.Threading.Tasks;\n+using Dapper;\n+using RapidCore.Migration;\n+using RapidCore.PostgreSql.Internal;\n+\n+namespace RapidCore.PostgreSql\n+{\n+    public class PostgreSqlMigrationStorage : IMigrationStorage\n+    {\n+        public async Task MarkAsCompleteAsync(IMigrationContext context, IMigration migration, long milliseconds)\n+        {\n+            var info = await GetMigrationInfoAsync(context, migration.Name);\n+            if (info == default(MigrationInfo))\n+            {\n+                info = new MigrationInfo\n+                {\n+                    Name = migration.Name\n+                };\n+            }\n+\n+            info.CompletedAtUtc = DateTime.UtcNow;\n+            info.MigrationCompleted = true;\n+            info.TotalMigrationTimeInMs = milliseconds;\n+\n+            await UpsertMigrationInfoAsync(context, info);\n+        }\n+\n+        private IDbConnection GetDb(IMigrationContext context)\n+        {\n+            return ((PostgreSqlMigrationContext) context).ConnectionProvider.Default();\n+        }\n+\n+        public async Task<MigrationInfo> GetMigrationInfoAsync(IMigrationContext context, string migrationName)\n+        {\n+            var db = GetDb(context);\n+            var migrationInfo = await db.QuerySingleOrDefaultAsync<MigrationInfo>($\"select * from {PostgreSqlConstants.MigrationInfoTableName} where Name = @MigrationName\",\n+                new {\n+                    MigrationName = migrationName\n+                });\n+            return migrationInfo;\n+        }\n+\n+        public async Task UpsertMigrationInfoAsync(IMigrationContext context, MigrationInfo info)\n+        {\n+            var db = GetDb(context);\n+            long migrationInfoId = 0;\n+            string insertQuery = $@\"INSERT INTO {PostgreSqlConstants.MigrationInfoTableName}(\n+                                        Name,\n+                                        MigrationCompleted,\n+                                        TotalMigrationTimeInMs,\n+                                        CompletedAtUtc) \n+                                   VALUES (\n+                                        @Name,\n+                                        @MigrationCompleted,\n+                                        @TotalMigrationTimeInMs,\n+                                        @CompletedAtUtc)\n+                                   ON CONFLICT (name)\n+                                   DO UPDATE SET\n+                                        Name = @Name,\n+                                        MigrationCompleted = @MigrationCompleted,\n+                                        TotalMigrationTimeInMs = @TotalMigrationTimeInMs,\n+                                        CompletedAtUtc = @CompletedAtUtc\n+                                   RETURNING id\";\n+\n+            using (var reader = await db.ExecuteReaderAsync(insertQuery, new\n+            {\n+                Name = info.Name,\n+                MigrationCompleted = info.MigrationCompleted,\n+                TotalMigrationTimeInMs = info.TotalMigrationTimeInMs,\n+                CompletedAtUtc = info.CompletedAtUtc\n+            }))\n+            {\n+                while (reader.Read())\n+                {\n+                    migrationInfoId = reader.GetInt64(0);\n+                }\n+            }\n+            foreach (var stepName in info.StepsCompleted)\n+            {\n+                string completedStepInsertQuery = $@\"INSERT INTO {PostgreSqlConstants.CompletedStepsTableName}(\n+                                        StepName,\n+                                        MigrationInfoId)\n+                                   VALUES (\n+                                        @StepName,\n+                                        @MigrationInfoId)\n+                                   ON CONFLICT (StepName, MigrationInfoId)\n+                                   DO NOTHING\n+                                    \";\n+\n+                await db.ExecuteAsync(completedStepInsertQuery, new\n+                {\n+                    StepName = stepName,\n+                    MigrationInfoId = migrationInfoId\n+                });\n+\n+            }\n+        }\n+\n+        public async Task<bool> HasMigrationBeenFullyCompletedAsync(IMigrationContext context, string migrationName)\n+        {\n+            // this is the de facto entry point via the migration runner, so create the table if it doesn't exist","path":"src/postgresql/main/PostgreSqlMigrationStorage.cs","position":null,"original_position":105,"commit_id":"c79916ae980c9a3c85f07821a8676e906904b5e1","original_commit_id":"f86be51d7bdd2069615082a44546ecb5a765887a","user":{"login":"MartinsRui","id":26538777,"avatar_url":"https://avatars2.githubusercontent.com/u/26538777?v=4","gravatar_id":"","url":"https://api.github.com/users/MartinsRui","html_url":"https://github.com/MartinsRui","followers_url":"https://api.github.com/users/MartinsRui/followers","following_url":"https://api.github.com/users/MartinsRui/following{/other_user}","gists_url":"https://api.github.com/users/MartinsRui/gists{/gist_id}","starred_url":"https://api.github.com/users/MartinsRui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MartinsRui/subscriptions","organizations_url":"https://api.github.com/users/MartinsRui/orgs","repos_url":"https://api.github.com/users/MartinsRui/repos","events_url":"https://api.github.com/users/MartinsRui/events{/privacy}","received_events_url":"https://api.github.com/users/MartinsRui/received_events","type":"User","site_admin":false},"body":"fixed.","created_at":"2018-03-02T15:24:24Z","updated_at":"2018-03-02T15:24:24Z","html_url":"https://github.com/rapidcore/rapidcore/pull/36#discussion_r171875554","pull_request_url":"https://api.github.com/repos/rapidcore/rapidcore/pulls/36","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/rapidcore/rapidcore/pulls/comments/171875554"},"html":{"href":"https://github.com/rapidcore/rapidcore/pull/36#discussion_r171875554"},"pull_request":{"href":"https://api.github.com/repos/rapidcore/rapidcore/pulls/36"}},"in_reply_to_id":171476375},"pull_request":{"url":"https://api.github.com/repos/rapidcore/rapidcore/pulls/36","id":170976961,"html_url":"https://github.com/rapidcore/rapidcore/pull/36","diff_url":"https://github.com/rapidcore/rapidcore/pull/36.diff","patch_url":"https://github.com/rapidcore/rapidcore/pull/36.patch","issue_url":"https://api.github.com/repos/rapidcore/rapidcore/issues/36","number":36,"state":"open","locked":false,"title":"postgresql migration feature","user":{"login":"MartinsRui","id":26538777,"avatar_url":"https://avatars2.githubusercontent.com/u/26538777?v=4","gravatar_id":"","url":"https://api.github.com/users/MartinsRui","html_url":"https://github.com/MartinsRui","followers_url":"https://api.github.com/users/MartinsRui/followers","following_url":"https://api.github.com/users/MartinsRui/following{/other_user}","gists_url":"https://api.github.com/users/MartinsRui/gists{/gist_id}","starred_url":"https://api.github.com/users/MartinsRui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MartinsRui/subscriptions","organizations_url":"https://api.github.com/users/MartinsRui/orgs","repos_url":"https://api.github.com/users/MartinsRui/repos","events_url":"https://api.github.com/users/MartinsRui/events{/privacy}","received_events_url":"https://api.github.com/users/MartinsRui/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-02-23T10:11:47Z","updated_at":"2018-03-02T15:24:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"120b1315e2a0656e05af345463059f99e48fd772","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/rapidcore/rapidcore/pulls/36/commits","review_comments_url":"https://api.github.com/repos/rapidcore/rapidcore/pulls/36/comments","review_comment_url":"https://api.github.com/repos/rapidcore/rapidcore/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rapidcore/rapidcore/issues/36/comments","statuses_url":"https://api.github.com/repos/rapidcore/rapidcore/statuses/c79916ae980c9a3c85f07821a8676e906904b5e1","head":{"label":"rapidcore:feature/migrations-postgresql","ref":"feature/migrations-postgresql","sha":"c79916ae980c9a3c85f07821a8676e906904b5e1","user":{"login":"rapidcore","id":28752420,"avatar_url":"https://avatars1.githubusercontent.com/u/28752420?v=4","gravatar_id":"","url":"https://api.github.com/users/rapidcore","html_url":"https://github.com/rapidcore","followers_url":"https://api.github.com/users/rapidcore/followers","following_url":"https://api.github.com/users/rapidcore/following{/other_user}","gists_url":"https://api.github.com/users/rapidcore/gists{/gist_id}","starred_url":"https://api.github.com/users/rapidcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rapidcore/subscriptions","organizations_url":"https://api.github.com/users/rapidcore/orgs","repos_url":"https://api.github.com/users/rapidcore/repos","events_url":"https://api.github.com/users/rapidcore/events{/privacy}","received_events_url":"https://api.github.com/users/rapidcore/received_events","type":"Organization","site_admin":false},"repo":{"id":91556892,"name":"rapidcore","full_name":"rapidcore/rapidcore","owner":{"login":"rapidcore","id":28752420,"avatar_url":"https://avatars1.githubusercontent.com/u/28752420?v=4","gravatar_id":"","url":"https://api.github.com/users/rapidcore","html_url":"https://github.com/rapidcore","followers_url":"https://api.github.com/users/rapidcore/followers","following_url":"https://api.github.com/users/rapidcore/following{/other_user}","gists_url":"https://api.github.com/users/rapidcore/gists{/gist_id}","starred_url":"https://api.github.com/users/rapidcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rapidcore/subscriptions","organizations_url":"https://api.github.com/users/rapidcore/orgs","repos_url":"https://api.github.com/users/rapidcore/repos","events_url":"https://api.github.com/users/rapidcore/events{/privacy}","received_events_url":"https://api.github.com/users/rapidcore/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rapidcore/rapidcore","description":"The stuff that seems to be missing from dotnet Core.","fork":false,"url":"https://api.github.com/repos/rapidcore/rapidcore","forks_url":"https://api.github.com/repos/rapidcore/rapidcore/forks","keys_url":"https://api.github.com/repos/rapidcore/rapidcore/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rapidcore/rapidcore/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rapidcore/rapidcore/teams","hooks_url":"https://api.github.com/repos/rapidcore/rapidcore/hooks","issue_events_url":"https://api.github.com/repos/rapidcore/rapidcore/issues/events{/number}","events_url":"https://api.github.com/repos/rapidcore/rapidcore/events","assignees_url":"https://api.github.com/repos/rapidcore/rapidcore/assignees{/user}","branches_url":"https://api.github.com/repos/rapidcore/rapidcore/branches{/branch}","tags_url":"https://api.github.com/repos/rapidcore/rapidcore/tags","blobs_url":"https://api.github.com/repos/rapidcore/rapidcore/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rapidcore/rapidcore/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rapidcore/rapidcore/git/refs{/sha}","trees_url":"https://api.github.com/repos/rapidcore/rapidcore/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rapidcore/rapidcore/statuses/{sha}","languages_url":"https://api.github.com/repos/rapidcore/rapidcore/languages","stargazers_url":"https://api.github.com/repos/rapidcore/rapidcore/stargazers","contributors_url":"https://api.github.com/repos/rapidcore/rapidcore/contributors","subscribers_url":"https://api.github.com/repos/rapidcore/rapidcore/subscribers","subscription_url":"https://api.github.com/repos/rapidcore/rapidcore/subscription","commits_url":"https://api.github.com/repos/rapidcore/rapidcore/commits{/sha}","git_commits_url":"https://api.github.com/repos/rapidcore/rapidcore/git/commits{/sha}","comments_url":"https://api.github.com/repos/rapidcore/rapidcore/comments{/number}","issue_comment_url":"https://api.github.com/repos/rapidcore/rapidcore/issues/comments{/number}","contents_url":"https://api.github.com/repos/rapidcore/rapidcore/contents/{+path}","compare_url":"https://api.github.com/repos/rapidcore/rapidcore/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rapidcore/rapidcore/merges","archive_url":"https://api.github.com/repos/rapidcore/rapidcore/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rapidcore/rapidcore/downloads","issues_url":"https://api.github.com/repos/rapidcore/rapidcore/issues{/number}","pulls_url":"https://api.github.com/repos/rapidcore/rapidcore/pulls{/number}","milestones_url":"https://api.github.com/repos/rapidcore/rapidcore/milestones{/number}","notifications_url":"https://api.github.com/repos/rapidcore/rapidcore/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rapidcore/rapidcore/labels{/name}","releases_url":"https://api.github.com/repos/rapidcore/rapidcore/releases{/id}","deployments_url":"https://api.github.com/repos/rapidcore/rapidcore/deployments","created_at":"2017-05-17T09:11:44Z","updated_at":"2018-01-25T07:20:34Z","pushed_at":"2018-03-02T15:17:15Z","git_url":"git://github.com/rapidcore/rapidcore.git","ssh_url":"git@github.com:rapidcore/rapidcore.git","clone_url":"https://github.com/rapidcore/rapidcore.git","svn_url":"https://github.com/rapidcore/rapidcore","homepage":"http://docs.rapidcore.io/","size":2820,"stargazers_count":2,"watchers_count":2,"language":"C#","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":14,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":14,"watchers":2,"default_branch":"master"}},"base":{"label":"rapidcore:master","ref":"master","sha":"a1b7b4e76c6964a08f568b4a98e1dcdf1f17208c","user":{"login":"rapidcore","id":28752420,"avatar_url":"https://avatars1.githubusercontent.com/u/28752420?v=4","gravatar_id":"","url":"https://api.github.com/users/rapidcore","html_url":"https://github.com/rapidcore","followers_url":"https://api.github.com/users/rapidcore/followers","following_url":"https://api.github.com/users/rapidcore/following{/other_user}","gists_url":"https://api.github.com/users/rapidcore/gists{/gist_id}","starred_url":"https://api.github.com/users/rapidcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rapidcore/subscriptions","organizations_url":"https://api.github.com/users/rapidcore/orgs","repos_url":"https://api.github.com/users/rapidcore/repos","events_url":"https://api.github.com/users/rapidcore/events{/privacy}","received_events_url":"https://api.github.com/users/rapidcore/received_events","type":"Organization","site_admin":false},"repo":{"id":91556892,"name":"rapidcore","full_name":"rapidcore/rapidcore","owner":{"login":"rapidcore","id":28752420,"avatar_url":"https://avatars1.githubusercontent.com/u/28752420?v=4","gravatar_id":"","url":"https://api.github.com/users/rapidcore","html_url":"https://github.com/rapidcore","followers_url":"https://api.github.com/users/rapidcore/followers","following_url":"https://api.github.com/users/rapidcore/following{/other_user}","gists_url":"https://api.github.com/users/rapidcore/gists{/gist_id}","starred_url":"https://api.github.com/users/rapidcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rapidcore/subscriptions","organizations_url":"https://api.github.com/users/rapidcore/orgs","repos_url":"https://api.github.com/users/rapidcore/repos","events_url":"https://api.github.com/users/rapidcore/events{/privacy}","received_events_url":"https://api.github.com/users/rapidcore/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rapidcore/rapidcore","description":"The stuff that seems to be missing from dotnet Core.","fork":false,"url":"https://api.github.com/repos/rapidcore/rapidcore","forks_url":"https://api.github.com/repos/rapidcore/rapidcore/forks","keys_url":"https://api.github.com/repos/rapidcore/rapidcore/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rapidcore/rapidcore/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rapidcore/rapidcore/teams","hooks_url":"https://api.github.com/repos/rapidcore/rapidcore/hooks","issue_events_url":"https://api.github.com/repos/rapidcore/rapidcore/issues/events{/number}","events_url":"https://api.github.com/repos/rapidcore/rapidcore/events","assignees_url":"https://api.github.com/repos/rapidcore/rapidcore/assignees{/user}","branches_url":"https://api.github.com/repos/rapidcore/rapidcore/branches{/branch}","tags_url":"https://api.github.com/repos/rapidcore/rapidcore/tags","blobs_url":"https://api.github.com/repos/rapidcore/rapidcore/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rapidcore/rapidcore/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rapidcore/rapidcore/git/refs{/sha}","trees_url":"https://api.github.com/repos/rapidcore/rapidcore/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rapidcore/rapidcore/statuses/{sha}","languages_url":"https://api.github.com/repos/rapidcore/rapidcore/languages","stargazers_url":"https://api.github.com/repos/rapidcore/rapidcore/stargazers","contributors_url":"https://api.github.com/repos/rapidcore/rapidcore/contributors","subscribers_url":"https://api.github.com/repos/rapidcore/rapidcore/subscribers","subscription_url":"https://api.github.com/repos/rapidcore/rapidcore/subscription","commits_url":"https://api.github.com/repos/rapidcore/rapidcore/commits{/sha}","git_commits_url":"https://api.github.com/repos/rapidcore/rapidcore/git/commits{/sha}","comments_url":"https://api.github.com/repos/rapidcore/rapidcore/comments{/number}","issue_comment_url":"https://api.github.com/repos/rapidcore/rapidcore/issues/comments{/number}","contents_url":"https://api.github.com/repos/rapidcore/rapidcore/contents/{+path}","compare_url":"https://api.github.com/repos/rapidcore/rapidcore/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rapidcore/rapidcore/merges","archive_url":"https://api.github.com/repos/rapidcore/rapidcore/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rapidcore/rapidcore/downloads","issues_url":"https://api.github.com/repos/rapidcore/rapidcore/issues{/number}","pulls_url":"https://api.github.com/repos/rapidcore/rapidcore/pulls{/number}","milestones_url":"https://api.github.com/repos/rapidcore/rapidcore/milestones{/number}","notifications_url":"https://api.github.com/repos/rapidcore/rapidcore/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rapidcore/rapidcore/labels{/name}","releases_url":"https://api.github.com/repos/rapidcore/rapidcore/releases{/id}","deployments_url":"https://api.github.com/repos/rapidcore/rapidcore/deployments","created_at":"2017-05-17T09:11:44Z","updated_at":"2018-01-25T07:20:34Z","pushed_at":"2018-03-02T15:17:15Z","git_url":"git://github.com/rapidcore/rapidcore.git","ssh_url":"git@github.com:rapidcore/rapidcore.git","clone_url":"https://github.com/rapidcore/rapidcore.git","svn_url":"https://github.com/rapidcore/rapidcore","homepage":"http://docs.rapidcore.io/","size":2820,"stargazers_count":2,"watchers_count":2,"language":"C#","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":14,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":14,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rapidcore/rapidcore/pulls/36"},"html":{"href":"https://github.com/rapidcore/rapidcore/pull/36"},"issue":{"href":"https://api.github.com/repos/rapidcore/rapidcore/issues/36"},"comments":{"href":"https://api.github.com/repos/rapidcore/rapidcore/issues/36/comments"},"review_comments":{"href":"https://api.github.com/repos/rapidcore/rapidcore/pulls/36/comments"},"review_comment":{"href":"https://api.github.com/repos/rapidcore/rapidcore/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rapidcore/rapidcore/pulls/36/commits"},"statuses":{"href":"https://api.github.com/repos/rapidcore/rapidcore/statuses/c79916ae980c9a3c85f07821a8676e906904b5e1"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"MartinsRui"}}