xmigra 1.6.3 → 1.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/xmigra/declarative_support/table.rb +28 -12
- data/lib/xmigra/vcs_support/git.rb +2 -2
- data/lib/xmigra/version.rb +1 -1
- data/test/git_vcs.rb +51 -0
- data/test/structure_declarative.rb +29 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f8a897f40302df5b84071bf9088b787c7be65fa
|
4
|
+
data.tar.gz: 1445c109f2e4fb2f58aa2f2407660c5b472a45cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8edd159507c099b6d6c16c99a5883cbad161025e6de3076fbe83465f4054e17da85c21b1c25e9b49bdc47e06cef46d9cd8cdb235b4a742ce42974df56fdbd0f5
|
7
|
+
data.tar.gz: 4b22d1239184bb5a44886db39ef5ccc8b8b569530bc495f8ab509e0a9df9272cd70e87e355210372a2d24b656271a5926005ae08d130392bbfbdbe40f45d26fa
|
@@ -40,14 +40,20 @@ is a sequence of column names. Only one primary key constraint may be
|
|
40
40
|
specified, whether through use of "primary key" keys in column mappings or
|
41
41
|
explicitly in the "constraints" section. For foreign key constraint
|
42
42
|
definitions, the value of the "columns" key must be a mapping of referring
|
43
|
-
column name to referenced column name
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
the prefix
|
43
|
+
column name to referenced column name and a "link to" key, whose value gives
|
44
|
+
the name of the relation referenced, must be given. Check constraint
|
45
|
+
definitions must have a "verify" key whose value is an SQL expression to be
|
46
|
+
checked for all records. Default constraints (when given explicitly) must
|
47
|
+
have a "value" key giving the expression (with possible limitations imposed by
|
48
|
+
the database system in use) for the default value and an indication of the
|
49
|
+
constrained column: either a "column" key giving explicit reference to a
|
50
|
+
column or, if the constraint name starts with the implicit prefix, the part of
|
51
|
+
the constraint name after the prefix.
|
52
|
+
|
53
|
+
In addition to the required keys, foreign key constraints support two optional
|
54
|
+
keys: "on update" and "on delete". These keys support generating "ON UPDATE"
|
55
|
+
and "ON DELETE" rules in the foreign key constraint creation SQL. The value
|
56
|
+
associated with the key is used in the SQL.
|
51
57
|
|
52
58
|
When specifying SQL expressions in YAML, make sure to use appropriate quoting.
|
53
59
|
For example, where apostrophes delimit string literals in SQL and it might be
|
@@ -404,6 +410,16 @@ END_OF_HELP
|
|
404
410
|
@columns_by_name.has_key? name
|
405
411
|
end
|
406
412
|
|
413
|
+
def add_column(colspec)
|
414
|
+
raise "Columns may not be added to the primary key after construction" if colspec['primary key']
|
415
|
+
Column.new(colspec).tap do |col|
|
416
|
+
@columns_by_name[col.name] = col
|
417
|
+
if !(col_default = col.default_constraint).nil?
|
418
|
+
@constraints[col_default.name] = col_default
|
419
|
+
end
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
407
423
|
def add_default(colname, expression, constr_name=nil)
|
408
424
|
col = get_column(colname)
|
409
425
|
unless col.default_constraint.nil?
|
@@ -449,7 +465,7 @@ END_OF_HELP
|
|
449
465
|
|
450
466
|
# Add new columns
|
451
467
|
parts.concat add_table_columns_sql_statements(
|
452
|
-
delta.new_columns
|
468
|
+
delta.new_columns
|
453
469
|
).to_a
|
454
470
|
|
455
471
|
# Alter existing columns
|
@@ -560,9 +576,9 @@ END_OF_HELP
|
|
560
576
|
end
|
561
577
|
end
|
562
578
|
|
563
|
-
def add_table_columns_sql_statements(
|
564
|
-
|
565
|
-
"ALTER TABLE #{name} ADD COLUMN #{
|
579
|
+
def add_table_columns_sql_statements(columns)
|
580
|
+
columns.map do |col|
|
581
|
+
"ALTER TABLE #{name} ADD COLUMN #{column_creation_sql_fragment(col)};"
|
566
582
|
end
|
567
583
|
end
|
568
584
|
|
@@ -293,7 +293,7 @@ module XMigra
|
|
293
293
|
args = []
|
294
294
|
|
295
295
|
commit = options.fetch(:revision, 'HEAD')
|
296
|
-
args << "#{commit}
|
296
|
+
args << "#{commit}:./#{path}"
|
297
297
|
|
298
298
|
git(:show, *args)
|
299
299
|
end
|
@@ -319,7 +319,7 @@ module XMigra
|
|
319
319
|
end
|
320
320
|
|
321
321
|
def vcs_uncommitted?
|
322
|
-
git_status == '??'
|
322
|
+
git_status == '??' || git_status[0] == 'A'
|
323
323
|
end
|
324
324
|
|
325
325
|
class VersionComparator
|
data/lib/xmigra/version.rb
CHANGED
data/test/git_vcs.rb
CHANGED
@@ -328,4 +328,55 @@ if GIT_PRESENT
|
|
328
328
|
end
|
329
329
|
end
|
330
330
|
end
|
331
|
+
|
332
|
+
run_test "XMigra recognizes files with changes in the index as uncommitted" do
|
333
|
+
test_object = Class.new do
|
334
|
+
include XMigra::GitSpecifics
|
335
|
+
def file_path
|
336
|
+
Pathname('foo.txt')
|
337
|
+
end
|
338
|
+
end.new
|
339
|
+
|
340
|
+
1.temp_dirs do |repo|
|
341
|
+
initialize_git_repo(repo)
|
342
|
+
|
343
|
+
Dir.chdir(repo) do
|
344
|
+
test_object.file_path.open('w') do |file|
|
345
|
+
file.puts 'bar'
|
346
|
+
end
|
347
|
+
|
348
|
+
do_or_die %Q{git add #{test_object.file_path}}
|
349
|
+
|
350
|
+
assert_eq(test_object.git_status, 'A ')
|
351
|
+
|
352
|
+
assert {test_object.vcs_uncommitted?} # After add
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
run_test "XMigra can retrieve content in a git subtree" do
|
358
|
+
test_object = Class.new do
|
359
|
+
include XMigra::GitSpecifics
|
360
|
+
def file_path
|
361
|
+
Pathname('foo.txt')
|
362
|
+
end
|
363
|
+
end.new
|
364
|
+
|
365
|
+
1.temp_dirs do |repo|
|
366
|
+
initialize_git_repo(repo)
|
367
|
+
|
368
|
+
(subdir = repo.join('subdir')).mkpath
|
369
|
+
|
370
|
+
Dir.chdir(subdir) do
|
371
|
+
test_object.file_path.open('w') do |file|
|
372
|
+
file.puts 'bar'
|
373
|
+
end
|
374
|
+
|
375
|
+
do_or_die %Q{git add #{test_object.file_path}}
|
376
|
+
do_or_die %Q{git commit -m "Committing"}
|
377
|
+
|
378
|
+
assert_eq(test_object.vcs_contents(test_object.file_path), "bar\n")
|
379
|
+
end
|
380
|
+
end
|
381
|
+
end
|
331
382
|
end
|
@@ -808,4 +808,33 @@ run_test "DeclarativeSupport::Table can alter an existing default constraint on
|
|
808
808
|
"CONSTRAINT DF_WEAPON DEFAULT 'ROCK' FOR WEAPON"
|
809
809
|
)
|
810
810
|
end
|
811
|
+
end
|
812
|
+
|
813
|
+
run_test "DeclarativeSupport::Table can add a NOT NULL column" do
|
814
|
+
in_xmigra_schema do
|
815
|
+
do_or_die "git init", "Unable to initialize git repository"
|
816
|
+
decl_file = add_foo_declarative
|
817
|
+
do_or_die %Q{git add #{decl_file}}
|
818
|
+
do_or_die %Q{git commit -m "Committing foo"}
|
819
|
+
|
820
|
+
deserializer = XMigra::ImpdeclMigrationAdder::SupportedObjectDeserializer.new(decl_file.basename('.yaml').to_s, XMigra::PgSQLSpecifics)
|
821
|
+
table_yaml = YAML.parse_file(decl_file)
|
822
|
+
table_old = deserializer.deserialize(table_yaml.children[0])
|
823
|
+
table_new = deserializer.deserialize(table_yaml.children[0])
|
824
|
+
table_new.add_column(
|
825
|
+
'name' => 'damage',
|
826
|
+
'type' => 'float',
|
827
|
+
'nullable' => false,
|
828
|
+
)
|
829
|
+
|
830
|
+
delta = XMigra::DeclarativeSupport::Table::Delta.new(table_old, table_new)
|
831
|
+
assert_eq(delta.constraints_to_drop, [])
|
832
|
+
assert_eq(delta.new_columns.length, 1)
|
833
|
+
assert_eq(delta.removed_columns, [])
|
834
|
+
assert_eq(delta.new_constraint_sql_clauses, [])
|
835
|
+
assert_eq(delta.altered_column_pairs, [])
|
836
|
+
stmts = table_new.add_table_columns_sql_statements(delta.new_columns)
|
837
|
+
assert_eq(stmts.length, 1)
|
838
|
+
assert_include(stmts[0], /NOT\s+NULL/)
|
839
|
+
end
|
811
840
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xmigra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Next IT Corporation
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-02-
|
12
|
+
date: 2016-02-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|