fixie 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fixie.gemspec +1 -1
- data/lib/fixie.rb +30 -19
- data/lib/fixie/version.rb +1 -1
- 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: cf8ccf1b8d2425c0d7c0f5ff010bc855b543660f
|
4
|
+
data.tar.gz: 79b5f737d75f04e4ded85b6edbf2e7b8f5f62d76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 152e1c87de693a844abb68a44a0bb261293c801caa42ee54d96b3f3cb56a3152b45cdc5cfc5f6743bd463e862b01dedcacc6cbcd0fd1a1a9edb0141371a554c8
|
7
|
+
data.tar.gz: fcc429a2648ea9bcd11d4df13a56607dc441ed747c14ae634af599ae18fefb94ad566af0d48b8ff028b76dc8bdade174dfec35b04c168f8ce5e7077f1c257bc5
|
data/fixie.gemspec
CHANGED
data/lib/fixie.rb
CHANGED
@@ -3,6 +3,7 @@ require 'active_support'
|
|
3
3
|
require 'active_support/core_ext'
|
4
4
|
require 'erb'
|
5
5
|
require 'sequel'
|
6
|
+
require 'set'
|
6
7
|
require 'yaml'
|
7
8
|
require 'zlib'
|
8
9
|
|
@@ -64,33 +65,43 @@ module Fixie
|
|
64
65
|
end
|
65
66
|
|
66
67
|
# Do a second pass to resolve associations and load data in DB
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
db.transaction(deferrable: true) do
|
69
|
+
all_fixtures[db_name].each do |table_name, fixtures|
|
70
|
+
table = db[table_name]
|
71
|
+
table.truncate(cascade: true, restart: true)
|
72
|
+
table_has_created_at = table.columns.include?(:created_at)
|
73
|
+
table_has_updated_at = table.columns.include?(:updated_at)
|
74
|
+
|
75
|
+
json_columns = Set.new
|
76
|
+
db.schema(table_name).each do |column,metadata|
|
77
|
+
json_columns << column if metadata[:db_type] == 'json'
|
78
|
+
end
|
72
79
|
|
73
|
-
|
80
|
+
fixtures.each do |name, data|
|
81
|
+
|
82
|
+
# Change attributes like city: baltimore to city_id: baltimore.id
|
83
|
+
data.keys.each do |attr|
|
84
|
+
associated_fixtures = all_fixtures[db_name][attr.to_s.pluralize.to_sym]
|
85
|
+
if associated_fixtures && table.columns.include?("#{attr}_id".to_sym)
|
86
|
+
associated_fixture = associated_fixtures[data[attr].to_sym]
|
87
|
+
if associated_fixture
|
88
|
+
data["#{attr}_id".to_sym] = associated_fixture[:id]
|
89
|
+
data.delete(attr)
|
90
|
+
end
|
91
|
+
end
|
74
92
|
|
75
|
-
|
76
|
-
|
77
|
-
associated_fixtures = all_fixtures[db_name][attr.to_s.pluralize.to_sym]
|
78
|
-
if associated_fixtures && table.columns.include?("#{attr}_id".to_sym)
|
79
|
-
associated_fixture = associated_fixtures[data[attr].to_sym]
|
80
|
-
if associated_fixture
|
81
|
-
data["#{attr}_id".to_sym] = associated_fixture[:id]
|
82
|
-
data.delete(attr)
|
93
|
+
if db.database_type == :postgres && json_columns.include?(attr)
|
94
|
+
data[attr] = Sequel.pg_json(data[attr])
|
83
95
|
end
|
84
96
|
end
|
85
97
|
|
98
|
+
# Set created_at/updated_at if they exist
|
86
99
|
data[:created_at] = now if table_has_created_at && !data.key?(:created_at)
|
87
100
|
data[:updated_at] = now if table_has_updated_at && !data.key?(:updated_at)
|
88
|
-
end
|
89
|
-
|
90
|
-
# Set created_at/updated_at if they exist
|
91
101
|
|
92
|
-
|
93
|
-
|
102
|
+
# Finally, replace the data in the DB
|
103
|
+
table.insert(data)
|
104
|
+
end
|
94
105
|
end
|
95
106
|
end
|
96
107
|
end
|
data/lib/fixie/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Barry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|