chronicler 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5c6897edb863ebbc3182d2b256a6c26d7d6763a
4
- data.tar.gz: a31860fa336b1002d751ecb8df6ae2834a529c6e
3
+ metadata.gz: 4601aca82d7b4e20ca7de0be13a4b5f3bc328eee
4
+ data.tar.gz: e87071d55ee8ff46c2715753dee4c5aca53934ae
5
5
  SHA512:
6
- metadata.gz: 4261895f88d52900c8e451eee93b04d40dfdf6feb30dfc889b95f75c41e087be53051e48abd47de3765e12753158d0070963866844f5700bfe2b1204e60778ba
7
- data.tar.gz: 90758496816f9b8516406ad909cb4dd138b00d50ec3a9191e9b322966a1fe7b9dff7c36862731f0570992626850278897ca8a2b75c86bb936d93e7532201ff10
6
+ metadata.gz: f7303884259d535ed74400f20b57cd9110419e22343f9f97f79a0b17876fd948144c89ca8035aaca03a036a7d961f218df009ccf669e1c155be4d449c7eb96b2
7
+ data.tar.gz: 2b2a631baec969a1ae3e4c360d91f723e678530b6f4421310f04ecece9cb8263a3a4e8b54e45e607286981d6b26375bd7f49427f9c50ec4d3e25e555d9a7aa33
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ ## Chronicler CHANGELOG
2
+
3
+ ### Version 0.1.2 (March 14, 2016)
4
+
5
+ * Fixed creating gzipped database dumps
6
+
7
+ ### Version 0.1.1 (March 4, 2016)
8
+
9
+ * Being able to move a tag during commit
10
+ * Improved `crn use`
11
+ * Being able to (Git) reset the current branch using `crn reset`
12
+ * Dumping tables separately ^^
13
+
14
+ ### Version 0.1.0 (March 3, 2016)
15
+
16
+ * Initial release
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Chronicler
1
+ # Chronicler [![Gem](https://img.shields.io/gem/v/chronicler.svg)](https://rubygems.org/gems/chronicler) [![Gem](https://img.shields.io/gem/dt/chronicler.svg)](https://rubygems.org/gems/chronicler)
2
2
 
3
3
  Version control your (development) databases using Git
4
4
 
@@ -12,19 +12,20 @@ Run the following command to install `Chronicler`:
12
12
 
13
13
  Chronicler is a command-line-tool so for starters, you can print help instructions:
14
14
 
15
- $ crn --help
15
+ $ crn help
16
16
  Commands:
17
17
  crn branch # List branches
18
18
  crn checkout [IDENTIFIER] # Switch and load the specified branch or commit or tag (IDENTIFIER is optional)
19
- crn commit # Commit current state of databases
19
+ crn commit # Commit current state of selected databases
20
20
  crn destroy # Remove Chronicler entirely
21
21
  crn help [COMMAND] # Describe available commands or one specific command
22
22
  crn init [NAME] # Create a new repository (NAME defaults to current Git repository or current user)
23
23
  crn list # List repositories
24
+ crn load # Load database(s) of current commit
24
25
  crn log [INTERFACE] # Show commit logs (INTERFACE is optional)
25
26
  crn new [BRANCH] # Create a new branch (BRANCH defaults to current Git branch)
26
27
  crn open # Open current repository
27
- crn reset # Reset database(s) to last commit
28
+ crn reset [COMMIT] # Reset current branch to specified commit
28
29
  crn select # Select which databases to store
29
30
  crn status # Show current status
30
31
  crn tree # Print branch graph tree
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.2
data/chronicler.gemspec CHANGED
@@ -1,4 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/chronicler/version", __FILE__)
2
3
 
3
4
  Gem::Specification.new do |gem|
4
5
  gem.authors = ["Paul Engel"]
@@ -12,7 +13,8 @@ Gem::Specification.new do |gem|
12
13
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
14
  gem.name = "chronicler"
14
15
  gem.require_paths = ["lib"]
15
- gem.version = "0.1.0"
16
+ gem.version = Chronicler::VERSION
17
+ gem.licenses = ["MIT"]
16
18
 
17
19
  gem.add_dependency "thor"
18
20
  gem.add_dependency "toml-rb"
@@ -16,17 +16,26 @@ class Chronicler
16
16
 
17
17
  desc "use [NAME]", "Use existing repository (NAME is optional)"
18
18
  def use(name = nil)
19
- name ||= begin
20
- current = current_name
21
- repositories = Chronicler.repositories - [current]
19
+ current = current_name
20
+ repositories = Chronicler.repositories - [current]
22
21
 
23
- no_repository_available! if repositories.empty?
22
+ if name == current
23
+ puts "Already using Chronicler repository '#{name}'."
24
+ exit!
25
+ end
24
26
 
27
+ name ||= begin
28
+ no_repository_available! if repositories.empty?
25
29
  postfix = " (on #{current})" if repositories.include?(current)
26
30
  repositories[Ask.list("Which repository do you want to use?#{postfix}", repositories)]
27
31
  end
28
32
 
29
- config_use name
33
+ unless repositories.include?(name)
34
+ puts "fatal: Chronicler repository '#{name}' does not exist."
35
+ exit!
36
+ end
37
+
38
+ config_use(name)
30
39
  end
31
40
 
32
41
  desc "open", "Open current repository"
@@ -68,13 +77,13 @@ class Chronicler
68
77
  else
69
78
  puts "Changes for commit:"
70
79
  puts
71
- (changes[:added] || []).each do |(table, checksum)|
80
+ changes[:added].each do |(table, checksum)|
72
81
  puts " added: #{table}"
73
82
  end
74
- (changes[:modified] || []).each do |(table, checksum)|
83
+ changes[:modified].each do |(table, checksum)|
75
84
  puts " modified: #{table} (#{checksum})"
76
85
  end
77
- (changes[:deleted] || []).each do |(table, checksum)|
86
+ changes[:deleted].each do |(table, checksum)|
78
87
  puts " deleted: #{table}"
79
88
  end
80
89
  puts
@@ -117,30 +126,40 @@ class Chronicler
117
126
  end
118
127
  selected = options.collect{|database| repository_databases.include?(database)}
119
128
 
120
- Ask.checkbox("Which databases would you like to store?", options, default: selected).each_with_index do |checked, index|
129
+ Ask.checkbox("Which database(s) would you like to store?", options, default: selected).each_with_index do |checked, index|
121
130
  databases << options[index] if checked
122
131
  end
123
132
 
124
133
  repository.select databases
125
134
  end
126
135
 
127
- desc "commit", "Commit current state of databases"
136
+ desc "commit", "Commit current state of selected databases"
128
137
  method_options [:message, "-m"] => :string, [:tag, "-t"] => :string
129
138
  def commit
130
139
  if repository.new?
131
140
  select
132
- elsif !repository.dirty?
133
- puts "Nothing to commit."
134
- return
141
+ else
142
+ unless repository.dirty?
143
+ puts "Nothing to commit."
144
+ exit!
145
+ end
146
+
147
+ if (tag = options[:tag]) && !repository.git("rev-parse #{tag}", :verbose).empty?
148
+ unless Ask.confirm("Tag '#{tag}' already exists. Do you want to move the tag?")
149
+ puts "fatal: Commit aborted."
150
+ exit!
151
+ end
152
+ end
135
153
  end
154
+
136
155
  message = options[:message] || "Updated databases"
137
- repository.commit message, options[:tag]
156
+ repository.commit message, tag
138
157
  end
139
158
 
140
- desc "reset", "Reset database(s) to last commit"
141
- def reset
142
- if repository && Ask.confirm("Are you sure you want to reset to the last commit? (Changes will be lost)")
143
- repository.reset
159
+ desc "load", "Load database(s) of current commit"
160
+ def load
161
+ if Ask.confirm("Are you sure you want to load databases from the #{repository.name.blue}:#{Git.head(repository.path)[0..7].yellow} commit? (Changes will be LOST)")
162
+ repository.load
144
163
  end
145
164
  end
146
165
 
@@ -159,6 +178,13 @@ class Chronicler
159
178
  puts "Successfully loaded database#{"s" unless repository.databases.size == 1} of '#{identifier}'"
160
179
  end
161
180
 
181
+ desc "reset [COMMIT]", "Reset current branch to specified commit"
182
+ def reset(commit)
183
+ if Ask.confirm("Are you sure you want to reset #{repository.name}:#{repository.branch} to #{commit.yellow}?")
184
+ repository.reset(commit)
185
+ end
186
+ end
187
+
162
188
  desc "destroy", "Remove Chronicler entirely"
163
189
  def destroy
164
190
  if File.exists?(Chronicler.config_path)
@@ -228,7 +254,7 @@ class Chronicler
228
254
  end
229
255
 
230
256
  def method_missing(method, *args)
231
- raise Error, "Unrecognized command \"#{method}\". Please consult `ds help`."
257
+ raise Error, "Unrecognized command \"#{method}\". Please consult `crn help`."
232
258
  end
233
259
 
234
260
  end
@@ -48,11 +48,15 @@ class Chronicler
48
48
  config[:"repository.checksums"] = checksums
49
49
  git "add ."
50
50
  git "commit -m #{message.inspect}"
51
- git "tag #{tag}" if tag
51
+ git "tag -f #{tag}" if tag
52
52
  end
53
53
 
54
- def reset
55
- load
54
+ def load
55
+ databases.each do |database|
56
+ Dir[File.join(path, database, "*.sql.gz")].each do |gzip|
57
+ run "gunzip < #{gzip} | mysql -u root #{database}"
58
+ end
59
+ end
56
60
  end
57
61
 
58
62
  def checkout(branch)
@@ -60,6 +64,10 @@ class Chronicler
60
64
  load
61
65
  end
62
66
 
67
+ def reset(commit)
68
+ git "reset --hard #{commit}"
69
+ end
70
+
63
71
  def git(command, output = :silence)
64
72
  run "git #{command}", output
65
73
  end
@@ -95,7 +103,9 @@ class Chronicler
95
103
  modified = current.select{|table, checksum| stored.keys.include?(table) && (stored[table] != checksum)}
96
104
  deleted = stored.reject{|table, checksum| current.keys.include?(table)}
97
105
 
98
- {}.tap do |changes|
106
+ Hash.new do |hash, key|
107
+ hash[key] = {}
108
+ end.tap do |changes|
99
109
  changes[:added] = added if added.any?
100
110
  changes[:modified] = modified if modified.any?
101
111
  changes[:deleted] = deleted if deleted.any?
@@ -121,22 +131,21 @@ class Chronicler
121
131
  end
122
132
 
123
133
  def dump
124
- Dir[File.join(path, "*.sql.gz")].each do |file|
125
- unless databases.include?(File.basename(file, ".sql.gz"))
126
- File.delete(file)
127
- end
128
- end
134
+ changed = changes
129
135
 
130
- changed = changes.values.flatten
131
- changed_databases = changed.collect{|h| h.keys.collect{|t| t.gsub(/-.*/, "")}}.flatten.uniq
132
- changed_databases.each do |database|
133
- run "mysqldump -u root #{database} | gzip -c | cat > #{database}.sql.gz", true
136
+ changed[:deleted].each do |table, checksum|
137
+ File.delete File.join(path, "#{table.gsub("-", File::SEPARATOR)}.sql.gz")
138
+ end
139
+ changed[:added].merge(changed[:modified]).each do |table, checksum|
140
+ database, table = table.split("-")
141
+ FileUtils.mkdir_p File.join(path, database)
142
+ run "mysqldump -u root #{database} #{table} | gzip -c | cat > #{File.join(database, table)}.sql.gz", true
134
143
  end
135
- end
136
144
 
137
- def load
138
- databases.each do |database|
139
- run "gunzip < #{database}.sql.gz | mysql -u root #{database}", true
145
+ Dir[File.join(path, "*")].each do |file|
146
+ if File.directory?(file) && Dir["#{File.join(file, "*.sql.gz")}"].empty?
147
+ FileUtils.rm_rf file
148
+ end
140
149
  end
141
150
  end
142
151
 
@@ -0,0 +1,7 @@
1
+ class Chronicler
2
+ MAJOR = 0
3
+ MINOR = 1
4
+ TINY = 2
5
+
6
+ VERSION = [MAJOR, MINOR, TINY].join(".")
7
+ end
data/lib/chronicler.rb CHANGED
@@ -4,6 +4,7 @@ require "chronicler/core_ext"
4
4
  require "chronicler/config"
5
5
  require "chronicler/git"
6
6
  require "chronicler/repository"
7
+ require "chronicler/version"
7
8
 
8
9
  class Chronicler
9
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chronicler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Engel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-03 00:00:00.000000000 Z
11
+ date: 2016-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -75,6 +75,7 @@ extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - ".gitignore"
78
+ - CHANGELOG.md
78
79
  - Gemfile
79
80
  - MIT-LICENSE
80
81
  - README.md
@@ -89,8 +90,10 @@ files:
89
90
  - lib/chronicler/core_ext/string.rb
90
91
  - lib/chronicler/git.rb
91
92
  - lib/chronicler/repository.rb
93
+ - lib/chronicler/version.rb
92
94
  homepage: https://github.com/archan937/chronicler
93
- licenses: []
95
+ licenses:
96
+ - MIT
94
97
  metadata: {}
95
98
  post_install_message:
96
99
  rdoc_options: []