convergence 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fcf2eb1b4a4cc1cc52648e454b2ad4087dea84e
4
- data.tar.gz: f82751ac5a1a4749bbe7546905e1f2a2a6f4963a
3
+ metadata.gz: 206de6bb62a2051e7d5f97ffe26e85f7f1809e6e
4
+ data.tar.gz: e31e17a94d6a522eb3c4682bd23776ec55df3caf
5
5
  SHA512:
6
- metadata.gz: f3a8d474d2869584658a1b20d6408b349711477a43561e31cf11778490a33b730bbae3aead1131b2a5dd1ad188021ea7ded8e4c15adcd2fa238b1c11032c1720
7
- data.tar.gz: 5a1e4a4f8476e51e903c28ad22cbbd1f8b868b9be9ee51a80bd4308f758a8f26522c97b970fc966656dd4f2da225d25990ae32a63fd66a58ea9951eb3d11609f
6
+ metadata.gz: 2a50c6601f503efafbd4a3b5bd64029f05bb1d8f95802a42a10a4a9fda709ccbd791131ad426f96c21ea139cba8fc6acf4f66d90b4b9dd6f1838ebd4a6dee837
7
+ data.tar.gz: 8e575d10f0e2402b86b15b4685e48ad71c69bc181f1417fc2f676527aa4aec843579b1b844aa3c47140f2c5bb02d9a385d9ec2e86c356d2ff722cfe5aea481d9
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  tmp/
2
2
  tags
3
3
  database.yml
4
+ pkg/
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- convergence (0.0.1)
4
+ convergence (0.0.2)
5
5
  diff-lcs
6
6
  diffy
7
7
  mysql2
data/README.md CHANGED
@@ -3,6 +3,10 @@
3
3
  Convergence is a Database Schema management tools.
4
4
  Currently, This tools is support only MySQL.
5
5
 
6
+ It defines DB Schema using Convergence DSL(like Rails DSL).
7
+ For more information about Convergence DSL, See below 'Detail About Convergence DSL'.
8
+
9
+
6
10
  [![Build Status](https://travis-ci.org/nishio-dens/convergence.svg?branch=master)](https://travis-ci.org/nishio-dens/convergence)
7
11
 
8
12
  ## Installation
@@ -25,6 +29,101 @@ Or install it yourself as:
25
29
  gem install convergence
26
30
  ```
27
31
 
32
+ ## What's this?
33
+
34
+ ```
35
+ $ mysql -u root -e 'create database example_database;'
36
+ $ cat database.yml
37
+
38
+ adapter: mysql
39
+ database: example_database
40
+ host: 127.0.0.1
41
+ username: root
42
+ password:
43
+
44
+ $ cat example.schema
45
+
46
+ create_table 'test_tables' do |t|
47
+ t.int :id, primary_key: true, extra: 'auto_increment'
48
+ t.varchar :name, limit: 100, null: true
49
+ t.datetime :created_at
50
+ t.datetime :updated_at
51
+
52
+ t.index :name
53
+ end
54
+
55
+ $ convergence -c database.yml -i example.schema --dryrun
56
+
57
+ #
58
+ #
59
+ # CREATE TABLE `test_tables` (
60
+ # `id` int(11) NOT NULL AUTO_INCREMENT,
61
+ # `name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
62
+ # `created_at` datetime NOT NULL,
63
+ # `updated_at` datetime NOT NULL,
64
+ # PRIMARY KEY (`id`),
65
+ # KEY `index_test_tables_on_name` (`name`)
66
+ # ) ENGINE=InnoDB ROW_FORMAT=Compact DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci;
67
+
68
+ $ convergence -c database.yml -i example.schema --apply
69
+
70
+ SET FOREIGN_KEY_CHECKS=0;
71
+ --> 0.000794s
72
+ CREATE TABLE `test_tables` (
73
+ `id` int(11) NOT NULL AUTO_INCREMENT,
74
+ `name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
75
+ `created_at` datetime NOT NULL,
76
+ `updated_at` datetime NOT NULL,
77
+ PRIMARY KEY (`id`),
78
+ KEY `index_test_tables_on_name` (`name`)
79
+ ) ENGINE=InnoDB ROW_FORMAT=Compact DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci;
80
+ --> 0.01485s
81
+ SET FOREIGN_KEY_CHECKS=1;
82
+ --> 0.000115s
83
+
84
+ $ cat changed_example.schema
85
+
86
+ create_table 'test_tables', comment: 'Table Comment Test', engine: 'MyISAM' do |t|
87
+ t.int :id, primary_key: true, extra: 'auto_increment'
88
+ t.varchar :name, limit: 100, null: true
89
+ t.datetime :created_at
90
+ t.datetime :posted_at
91
+ end
92
+
93
+ $ convergence -c database.yml -i changed_example.schema --dryrun
94
+
95
+ # ALTER TABLE `test_tables` DROP COLUMN `updated_at`;
96
+ # ALTER TABLE `test_tables` ADD COLUMN `posted_at` datetime NOT NULL AFTER `created_at`;
97
+ # DROP INDEX `index_test_tables_on_name` ON `test_tables`;
98
+ # ALTER TABLE `test_tables` ENGINE=MyISAM COMMENT='Table Comment Test';
99
+
100
+ $ convergence -c database.yml -i changed_example.schema --apply
101
+ SET FOREIGN_KEY_CHECKS=0;
102
+ --> 0.000847s
103
+ ALTER TABLE `test_tables` DROP COLUMN `updated_at`;
104
+ --> 0.034026s
105
+ ALTER TABLE `test_tables` ADD COLUMN `posted_at` datetime NOT NULL AFTER `created_at`;
106
+ --> 0.025328s
107
+ DROP INDEX `index_test_tables_on_name` ON `test_tables`;
108
+ --> 0.011465s
109
+ ALTER TABLE `test_tables` ENGINE=MyISAM COMMENT='Table Comment Test';
110
+ --> 0.01115s
111
+ SET FOREIGN_KEY_CHECKS=1;
112
+ --> 0.000147s
113
+
114
+ $ mysql -u root example_database -e 'show create table test_tables\G'
115
+
116
+ *************************** 1. row ***************************
117
+ Table: test_tables
118
+ Create Table: CREATE TABLE `test_tables` (
119
+ `id` int(11) NOT NULL AUTO_INCREMENT,
120
+ `name` varchar(100) DEFAULT NULL,
121
+ `created_at` datetime NOT NULL,
122
+ `posted_at` datetime NOT NULL,
123
+ PRIMARY KEY (`id`)
124
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='Table Comment Test'
125
+ ```
126
+
28
127
  ## Usage
29
128
 
30
129
  ```
@@ -38,3 +137,165 @@ Usage: convergence [options]
38
137
  --apply execute sql to your database
39
138
  -h, --help Display this help message.
40
139
  ```
140
+
141
+ ### DB Config
142
+
143
+ You need to make database.yml to access your database.
144
+
145
+ ```
146
+ $ cat database.yml
147
+ dapter: mysql
148
+ database: convergence_test
149
+ host: 127.0.0.1
150
+ username: root
151
+ password:
152
+ ```
153
+
154
+ ### Export Your DB Schema
155
+
156
+ First, you need to create database.yml.
157
+ And then, execute command like below.
158
+
159
+ ```
160
+ $ convergence -c database.yml --export > example.schema
161
+ ```
162
+
163
+ Export DSL like this.
164
+
165
+ ```
166
+ create_table "authors", collate: "utf8_general_ci" do |t|
167
+ t.int "id", primary_key: true, extra: "auto_increment"
168
+ t.varchar "name", limit: 110
169
+ t.datetime "created_at", null: true
170
+ t.datetime "updated_at", null: true
171
+
172
+ t.index "created_at", name: "index_authors_on_created_at"
173
+ end
174
+
175
+ create_table "papers", collate: "utf8_general_ci", comment: "Paper" do |t|
176
+ t.int "id", primary_key: true, extra: "auto_increment"
177
+ t.varchar "title1", limit: 300, comment: "Title 1"
178
+ t.varchar "title2", limit: 300, comment: "Title 2"
179
+ t.text "description", null: true, comment: "Description"
180
+ end
181
+
182
+ create_table "paper_authors", collate: "utf8_general_ci", comment: "Paper Author Relation" do |t|
183
+ t.int "id", primary_key: true, extra: "auto_increment"
184
+ t.int "paper_id", comment: "Paper id"
185
+ t.int "author_id", comment: "Paper author id"
186
+
187
+ t.foreign_key "author_id", reference: "authors", reference_column: "id", name: "paper_authors_author_id_fk"
188
+ t.foreign_key "paper_id", reference: "papers", reference_column: "id", name: "paper_authors_paper_id_fk"
189
+ end
190
+ ```
191
+
192
+ ### Dryrun
193
+
194
+ ```
195
+ $ convergence -c database.yml -i example.schema --dryrun
196
+ ```
197
+
198
+ ### Apply
199
+
200
+ ```
201
+ $ convergence -c database.yml -i example.schema --apply
202
+ ```
203
+
204
+ ## Detail About Convergence DSL
205
+
206
+ ### support column types
207
+
208
+ Convergence is currently support column types below.
209
+
210
+ - tinyint
211
+ - smallint
212
+ - mediumint
213
+ - int
214
+ - bigint
215
+ - float
216
+ - double
217
+ - decimal
218
+ - char
219
+ - varchar
220
+ - tinyblob
221
+ - blob
222
+ - mediumblob
223
+ - tinytext
224
+ - text
225
+ - mediumtext
226
+ - longtext
227
+ - date
228
+ - time
229
+ - datetime
230
+ - timestamp
231
+ - year
232
+
233
+ ```
234
+ create_table "tests", comment: 'Column type example' do |t|
235
+ t.int 'id', primary_key: true, extra: 'auto_increment'
236
+ t.float 'float_col', comment: 'Float column'
237
+ t.decimal 'decimal_col', default: "0.000", precision: 12, scale: 3
238
+ t.varchar 'test_string', null: true, default: 'hello', limit: 300
239
+ t.text 'text_col'
240
+ t.datetime 'created_at'
241
+ end
242
+ ```
243
+
244
+ ### index
245
+
246
+ ```
247
+ create_table "tests", comment: 'Index example' do |t|
248
+ t.int 'id', primary_key: true, extra: 'auto_increment'
249
+ t.varchar 'column1'
250
+ t.varchar 'column2'
251
+
252
+ t.index 'column1'
253
+ t.index ['column2', 'column1']
254
+ t.index 'column2', name: 'column2_idx'
255
+ end
256
+ ```
257
+
258
+ ### foreign key
259
+
260
+ ```
261
+ create_table "authors" do |t|
262
+ t.int "id", primary_key: true, extra: "auto_increment"
263
+ t.varchar "name", limit: 110
264
+ end
265
+
266
+ create_table "papers", collate: "utf8_general_ci", comment: "Paper" do |t|
267
+ t.int "id", primary_key: true, extra: "auto_increment"
268
+ t.varchar "title1"
269
+ end
270
+
271
+ create_table "paper_authors", collate: "utf8_general_ci", comment: "Paper Author Relation" do |t|
272
+ t.int "id", primary_key: true, extra: "auto_increment"
273
+ t.int "paper_id", comment: "Paper id"
274
+ t.int "author_id", comment: "Paper author id"
275
+
276
+ t.foreign_key "author_id", reference: "authors", reference_column: "id"
277
+ t.foreign_key "paper_id", reference: "papers", reference_column: "id", name: "paper_authors_paper_id_fk"
278
+ end
279
+
280
+ ```
281
+
282
+ ### table options
283
+
284
+ ```
285
+ create_table "authors", comment: 'Author', engine: 'MyISAM', collate: "utf8_general_ci", default_charset: 'utf8' do |t|
286
+ t.int "id", primary_key: true, extra: "auto_increment"
287
+ t.varchar "name", limit: 110
288
+ end
289
+ ```
290
+
291
+
292
+ ## Test
293
+
294
+ ```
295
+ $ bundle exec rake db:convergence:prepare
296
+ $ bundle exec rspec
297
+ ```
298
+
299
+ ## Copyright
300
+
301
+ Copyright © 2014 S.nishio. See LICENSE.txt for further details.
@@ -1,3 +1,3 @@
1
1
  module Convergence
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: convergence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shinsuke Nishio
@@ -183,7 +183,6 @@ files:
183
183
  - README.md
184
184
  - Rakefile
185
185
  - bin/convergence
186
- - convergence-0.0.1.gem
187
186
  - convergence.gemspec
188
187
  - database.yml.example
189
188
  - lib/convergence.rb
Binary file