{"action":"created","comment":{"url":"https://api.github.com/repos/CESNET/perun/pulls/comments/32613474","id":32613474,"diff_hunk":"@@ -73,4 +80,119 @@ public String getDatabaseInformation(PerunSession sess) throws InternalErrorExce\n \t\t\tthrow new InternalErrorException(ex);\n \t\t}\n \t}\n+\n+\tpublic String getCodeDatabaseVersion(String fileName) throws InternalErrorException {\n+\t\ttry(BufferedReader br = new BufferedReader(new InputStreamReader(ClassLoader.getSystemResourceAsStream(fileName)))) {\n+\n+\t\t\tPattern versionPattern = Pattern.compile(\"^[1-9][0-9]*[.][0-9]+[.][0-9]+\");\n+\t\t\tPattern commentPattern = Pattern.compile(\"^--.*\");\n+\n+\t\t\tString line = br.readLine();\n+\n+\t\t\twhile (line != null){\n+\t\t\t\tline = line.trim();\n+\n+\t\t\t\t// ignore empty lines and comments at the start of the file and between versions\n+\t\t\t\tif(line.isEmpty() || commentPattern.matcher(line).matches()) {\n+\t\t\t\t\tline = br.readLine();\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t\tif(versionPattern.matcher(line).matches()){\n+\t\t\t\t\treturn line;\n+\t\t\t\t} else {\n+\t\t\t\t\tthrow new InternalErrorException(\"Version does not match the pattern required in \" + fileName);\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tthrow new InternalErrorException(fileName + \" is empty\");\n+\n+\t\t} catch(IOException e) {\n+\t\t\tthrow new InternalErrorException(\"Error reading \" + fileName, e);\n+\t\t}\n+\t}\n+\n+\tpublic void updateDatabaseVersion(String currentDBVersion, String fileName) throws InternalErrorException {\n+\t\tList<DBVersion> versions = getChangelogVersions(currentDBVersion, fileName);\n+\t\tCollections.reverse(versions);\n+\n+\t\tfor (DBVersion v : versions) {\n+\t\t\tList<String> successfulCommands = new ArrayList<>();\n+\t\t\tfor (String c : v.getCommands()) {\n+\t\t\t\ttry {\n+\t\t\t\t\tjdbc.execute(c);\n+\t\t\t\t\tsuccessfulCommands.add(c);\n+\t\t\t\t} catch(EmptyResultDataAccessException ex) {\n+\t\t\t\t\tlog.error(\"Update unsuccessful. All versions before \" + v.getVersion() + \" were successfully executed. \" +\n+\t\t\t\t\t\t\t\"Error executing command in version \" + v.getVersion() + \": \" + c, ex);\n+\t\t\t\t\tlog.error(\"Successful commands from \" + v.getVersion() + \": \" + successfulCommands);\n+\t\t\t\t\tthrow new ConsistencyErrorException(\"Update unsuccessful. Error executing command in version \" + v.getVersion() + \": \" + c, ex);\n+\t\t\t\t} catch(RuntimeException ex) {\n+\t\t\t\t\tlog.error(\"Update unsuccessful. All versions before \" + v.getVersion() + \" were successfully executed. \" +\n+\t\t\t\t\t\t\t\"Error executing command in version \" + v.getVersion() + \": \" + c, ex);\n+\t\t\t\t\tlog.error(\"Successful commands from \" + v.getVersion() + \": \" + successfulCommands);\n+\t\t\t\t\tthrow new InternalErrorException(\"Update unsuccessful. Error executing command in version \" + v.getVersion() + \": \" + c, ex);\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\tpublic List<DBVersion> getChangelogVersions(String currentDBVersion, String fileName) throws InternalErrorException {\n+\n+\t\tPattern versionPattern = Pattern.compile(\"^[1-9][0-9]*[.][0-9]+[.][0-9]+\");\n+\t\tPattern commentPattern = Pattern.compile(\"^--.*\");\n+\n+\t\tList<DBVersion> versions = new ArrayList<>();\n+\t\tboolean versionFound = false;\n+\n+\t\ttry(BufferedReader br = new BufferedReader(new InputStreamReader(ClassLoader.getSystemResourceAsStream(fileName)))) {","path":"perun-core/src/main/java/cz/metacentrum/perun/core/impl/DatabaseManagerImpl.java","position":123,"original_position":123,"commit_id":"74979996812c0e2ed575162b831ec796deb50c7d","original_commit_id":"74979996812c0e2ed575162b831ec796deb50c7d","user":{"login":"stavamichal","id":5602147,"avatar_url":"https://avatars.githubusercontent.com/u/5602147?v=3","gravatar_id":"","url":"https://api.github.com/users/stavamichal","html_url":"https://github.com/stavamichal","followers_url":"https://api.github.com/users/stavamichal/followers","following_url":"https://api.github.com/users/stavamichal/following{/other_user}","gists_url":"https://api.github.com/users/stavamichal/gists{/gist_id}","starred_url":"https://api.github.com/users/stavamichal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stavamichal/subscriptions","organizations_url":"https://api.github.com/users/stavamichal/orgs","repos_url":"https://api.github.com/users/stavamichal/repos","events_url":"https://api.github.com/users/stavamichal/events{/privacy}","received_events_url":"https://api.github.com/users/stavamichal/received_events","type":"User","site_admin":false},"body":"Sorry, you are right, this is new syntax for me.","created_at":"2015-06-17T10:31:56Z","updated_at":"2015-06-17T10:31:56Z","html_url":"https://github.com/CESNET/perun/pull/730#discussion_r32613474","pull_request_url":"https://api.github.com/repos/CESNET/perun/pulls/730","_links":{"self":{"href":"https://api.github.com/repos/CESNET/perun/pulls/comments/32613474"},"html":{"href":"https://github.com/CESNET/perun/pull/730#discussion_r32613474"},"pull_request":{"href":"https://api.github.com/repos/CESNET/perun/pulls/730"}}},"pull_request":{"url":"https://api.github.com/repos/CESNET/perun/pulls/730","id":30893074,"html_url":"https://github.com/CESNET/perun/pull/730","diff_url":"https://github.com/CESNET/perun/pull/730.diff","patch_url":"https://github.com/CESNET/perun/pull/730.patch","issue_url":"https://api.github.com/repos/CESNET/perun/issues/730","number":730,"state":"open","locked":false,"title":"Initialization manager changes schema by changelog","user":{"login":"Simcsa","id":6998265,"avatar_url":"https://avatars.githubusercontent.com/u/6998265?v=3","gravatar_id":"","url":"https://api.github.com/users/Simcsa","html_url":"https://github.com/Simcsa","followers_url":"https://api.github.com/users/Simcsa/followers","following_url":"https://api.github.com/users/Simcsa/following{/other_user}","gists_url":"https://api.github.com/users/Simcsa/gists{/gist_id}","starred_url":"https://api.github.com/users/Simcsa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Simcsa/subscriptions","organizations_url":"https://api.github.com/users/Simcsa/orgs","repos_url":"https://api.github.com/users/Simcsa/repos","events_url":"https://api.github.com/users/Simcsa/events{/privacy}","received_events_url":"https://api.github.com/users/Simcsa/received_events","type":"User","site_admin":false},"body":"- initialization manager in DatabaseManagerBlImpl changes database version by changelog file in resources. It searches for the actual db version in the changelog file and executes all the commands of the newer version.\r\n- DBVersion bean created for saving db versions with their commands\r\n- tests to ensure that parsing of the changelog file works correctly were created. Test files created in resources in test folder.","created_at":"2015-03-10T21:12:42Z","updated_at":"2015-06-17T10:31:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"30d96be504aac6c8c58fd7cd1524fc03266125cd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/CESNET/perun/pulls/730/commits","review_comments_url":"https://api.github.com/repos/CESNET/perun/pulls/730/comments","review_comment_url":"https://api.github.com/repos/CESNET/perun/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CESNET/perun/issues/730/comments","statuses_url":"https://api.github.com/repos/CESNET/perun/statuses/74979996812c0e2ed575162b831ec796deb50c7d","head":{"label":"Simcsa:initializationManager","ref":"initializationManager","sha":"74979996812c0e2ed575162b831ec796deb50c7d","user":{"login":"Simcsa","id":6998265,"avatar_url":"https://avatars.githubusercontent.com/u/6998265?v=3","gravatar_id":"","url":"https://api.github.com/users/Simcsa","html_url":"https://github.com/Simcsa","followers_url":"https://api.github.com/users/Simcsa/followers","following_url":"https://api.github.com/users/Simcsa/following{/other_user}","gists_url":"https://api.github.com/users/Simcsa/gists{/gist_id}","starred_url":"https://api.github.com/users/Simcsa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Simcsa/subscriptions","organizations_url":"https://api.github.com/users/Simcsa/orgs","repos_url":"https://api.github.com/users/Simcsa/repos","events_url":"https://api.github.com/users/Simcsa/events{/privacy}","received_events_url":"https://api.github.com/users/Simcsa/received_events","type":"User","site_admin":false},"repo":{"id":20881239,"name":"perun","full_name":"Simcsa/perun","owner":{"login":"Simcsa","id":6998265,"avatar_url":"https://avatars.githubusercontent.com/u/6998265?v=3","gravatar_id":"","url":"https://api.github.com/users/Simcsa","html_url":"https://github.com/Simcsa","followers_url":"https://api.github.com/users/Simcsa/followers","following_url":"https://api.github.com/users/Simcsa/following{/other_user}","gists_url":"https://api.github.com/users/Simcsa/gists{/gist_id}","starred_url":"https://api.github.com/users/Simcsa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Simcsa/subscriptions","organizations_url":"https://api.github.com/users/Simcsa/orgs","repos_url":"https://api.github.com/users/Simcsa/repos","events_url":"https://api.github.com/users/Simcsa/events{/privacy}","received_events_url":"https://api.github.com/users/Simcsa/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Simcsa/perun","description":"Users, Groups, Services and Resources Management System","fork":true,"url":"https://api.github.com/repos/Simcsa/perun","forks_url":"https://api.github.com/repos/Simcsa/perun/forks","keys_url":"https://api.github.com/repos/Simcsa/perun/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Simcsa/perun/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Simcsa/perun/teams","hooks_url":"https://api.github.com/repos/Simcsa/perun/hooks","issue_events_url":"https://api.github.com/repos/Simcsa/perun/issues/events{/number}","events_url":"https://api.github.com/repos/Simcsa/perun/events","assignees_url":"https://api.github.com/repos/Simcsa/perun/assignees{/user}","branches_url":"https://api.github.com/repos/Simcsa/perun/branches{/branch}","tags_url":"https://api.github.com/repos/Simcsa/perun/tags","blobs_url":"https://api.github.com/repos/Simcsa/perun/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Simcsa/perun/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Simcsa/perun/git/refs{/sha}","trees_url":"https://api.github.com/repos/Simcsa/perun/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Simcsa/perun/statuses/{sha}","languages_url":"https://api.github.com/repos/Simcsa/perun/languages","stargazers_url":"https://api.github.com/repos/Simcsa/perun/stargazers","contributors_url":"https://api.github.com/repos/Simcsa/perun/contributors","subscribers_url":"https://api.github.com/repos/Simcsa/perun/subscribers","subscription_url":"https://api.github.com/repos/Simcsa/perun/subscription","commits_url":"https://api.github.com/repos/Simcsa/perun/commits{/sha}","git_commits_url":"https://api.github.com/repos/Simcsa/perun/git/commits{/sha}","comments_url":"https://api.github.com/repos/Simcsa/perun/comments{/number}","issue_comment_url":"https://api.github.com/repos/Simcsa/perun/issues/comments{/number}","contents_url":"https://api.github.com/repos/Simcsa/perun/contents/{+path}","compare_url":"https://api.github.com/repos/Simcsa/perun/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Simcsa/perun/merges","archive_url":"https://api.github.com/repos/Simcsa/perun/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Simcsa/perun/downloads","issues_url":"https://api.github.com/repos/Simcsa/perun/issues{/number}","pulls_url":"https://api.github.com/repos/Simcsa/perun/pulls{/number}","milestones_url":"https://api.github.com/repos/Simcsa/perun/milestones{/number}","notifications_url":"https://api.github.com/repos/Simcsa/perun/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Simcsa/perun/labels{/name}","releases_url":"https://api.github.com/repos/Simcsa/perun/releases{/id}","created_at":"2014-06-16T10:36:47Z","updated_at":"2015-04-21T12:49:09Z","pushed_at":"2015-06-13T15:49:43Z","git_url":"git://github.com/Simcsa/perun.git","ssh_url":"git@github.com:Simcsa/perun.git","clone_url":"https://github.com/Simcsa/perun.git","svn_url":"https://github.com/Simcsa/perun","homepage":null,"size":23479,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"CESNET:master","ref":"master","sha":"1d375808607bf20518989c3295918029a4ecde05","user":{"login":"CESNET","id":1116469,"avatar_url":"https://avatars.githubusercontent.com/u/1116469?v=3","gravatar_id":"","url":"https://api.github.com/users/CESNET","html_url":"https://github.com/CESNET","followers_url":"https://api.github.com/users/CESNET/followers","following_url":"https://api.github.com/users/CESNET/following{/other_user}","gists_url":"https://api.github.com/users/CESNET/gists{/gist_id}","starred_url":"https://api.github.com/users/CESNET/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CESNET/subscriptions","organizations_url":"https://api.github.com/users/CESNET/orgs","repos_url":"https://api.github.com/users/CESNET/repos","events_url":"https://api.github.com/users/CESNET/events{/privacy}","received_events_url":"https://api.github.com/users/CESNET/received_events","type":"Organization","site_admin":false},"repo":{"id":4085998,"name":"perun","full_name":"CESNET/perun","owner":{"login":"CESNET","id":1116469,"avatar_url":"https://avatars.githubusercontent.com/u/1116469?v=3","gravatar_id":"","url":"https://api.github.com/users/CESNET","html_url":"https://github.com/CESNET","followers_url":"https://api.github.com/users/CESNET/followers","following_url":"https://api.github.com/users/CESNET/following{/other_user}","gists_url":"https://api.github.com/users/CESNET/gists{/gist_id}","starred_url":"https://api.github.com/users/CESNET/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CESNET/subscriptions","organizations_url":"https://api.github.com/users/CESNET/orgs","repos_url":"https://api.github.com/users/CESNET/repos","events_url":"https://api.github.com/users/CESNET/events{/privacy}","received_events_url":"https://api.github.com/users/CESNET/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CESNET/perun","description":"Identity and Access Management System","fork":false,"url":"https://api.github.com/repos/CESNET/perun","forks_url":"https://api.github.com/repos/CESNET/perun/forks","keys_url":"https://api.github.com/repos/CESNET/perun/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CESNET/perun/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CESNET/perun/teams","hooks_url":"https://api.github.com/repos/CESNET/perun/hooks","issue_events_url":"https://api.github.com/repos/CESNET/perun/issues/events{/number}","events_url":"https://api.github.com/repos/CESNET/perun/events","assignees_url":"https://api.github.com/repos/CESNET/perun/assignees{/user}","branches_url":"https://api.github.com/repos/CESNET/perun/branches{/branch}","tags_url":"https://api.github.com/repos/CESNET/perun/tags","blobs_url":"https://api.github.com/repos/CESNET/perun/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CESNET/perun/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CESNET/perun/git/refs{/sha}","trees_url":"https://api.github.com/repos/CESNET/perun/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CESNET/perun/statuses/{sha}","languages_url":"https://api.github.com/repos/CESNET/perun/languages","stargazers_url":"https://api.github.com/repos/CESNET/perun/stargazers","contributors_url":"https://api.github.com/repos/CESNET/perun/contributors","subscribers_url":"https://api.github.com/repos/CESNET/perun/subscribers","subscription_url":"https://api.github.com/repos/CESNET/perun/subscription","commits_url":"https://api.github.com/repos/CESNET/perun/commits{/sha}","git_commits_url":"https://api.github.com/repos/CESNET/perun/git/commits{/sha}","comments_url":"https://api.github.com/repos/CESNET/perun/comments{/number}","issue_comment_url":"https://api.github.com/repos/CESNET/perun/issues/comments{/number}","contents_url":"https://api.github.com/repos/CESNET/perun/contents/{+path}","compare_url":"https://api.github.com/repos/CESNET/perun/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CESNET/perun/merges","archive_url":"https://api.github.com/repos/CESNET/perun/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CESNET/perun/downloads","issues_url":"https://api.github.com/repos/CESNET/perun/issues{/number}","pulls_url":"https://api.github.com/repos/CESNET/perun/pulls{/number}","milestones_url":"https://api.github.com/repos/CESNET/perun/milestones{/number}","notifications_url":"https://api.github.com/repos/CESNET/perun/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CESNET/perun/labels{/name}","releases_url":"https://api.github.com/repos/CESNET/perun/releases{/id}","created_at":"2012-04-20T11:55:38Z","updated_at":"2015-05-07T12:36:23Z","pushed_at":"2015-06-16T13:18:27Z","git_url":"git://github.com/CESNET/perun.git","ssh_url":"git@github.com:CESNET/perun.git","clone_url":"https://github.com/CESNET/perun.git","svn_url":"https://github.com/CESNET/perun","homepage":"http://perun.cesnet.cz","size":30255,"stargazers_count":11,"watchers_count":11,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":20,"mirror_url":null,"open_issues_count":7,"forks":20,"open_issues":7,"watchers":11,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CESNET/perun/pulls/730"},"html":{"href":"https://github.com/CESNET/perun/pull/730"},"issue":{"href":"https://api.github.com/repos/CESNET/perun/issues/730"},"comments":{"href":"https://api.github.com/repos/CESNET/perun/issues/730/comments"},"review_comments":{"href":"https://api.github.com/repos/CESNET/perun/pulls/730/comments"},"review_comment":{"href":"https://api.github.com/repos/CESNET/perun/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CESNET/perun/pulls/730/commits"},"statuses":{"href":"https://api.github.com/repos/CESNET/perun/statuses/74979996812c0e2ed575162b831ec796deb50c7d"}}}}