fides 0.0.11 → 0.0.13
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 +4 -4
- data/README.md +1 -1
- data/lib/fides/postgresql.rb +16 -3
- data/lib/fides/sqlite3.rb +84 -4
- data/lib/fides/version.rb +1 -1
- data/lib/fides.rb +5 -7
- data/test/lib/fides/postgresql_test.rb +62 -61
- data/test/lib/fides/sql_writer_test.rb +36 -0
- data/test/lib/fides/sqlite3_test.rb +107 -0
- data/test/lib/integration/postgresql_db_test.rb +0 -0
- data/test/lib/integration/sqlite3_db_test.rb +0 -0
- metadata +10 -4
- data/test/lib/fides/database_adapter_test.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6730418f04d57da6e4cbd55988a3c508009ee881
|
4
|
+
data.tar.gz: 89a9e627c96a5c215351e9223265c5b249ad88b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cccbd5ab8741d65b6bc26540ad1b59f9b0d336ceccb48680041e793ffea21464218a82a22b7a0af74b75e3a0d8a734121f7de4a6fa9965678e16698937436f3
|
7
|
+
data.tar.gz: 2d1c481246449df7bde5418a3f47a980c3b228e887793f6939209dcb01b4806cb9542d6b602c79b674086a346faa6f181e517d96625730a58a10f722a9e3b52e
|
data/README.md
CHANGED
@@ -71,7 +71,7 @@ If you're using Rails < version 3.1, then use Fides in your migration like this:
|
|
71
71
|
Fides assumes the use of Rails conventions, so if you find a case for something that needs overriding,
|
72
72
|
please feel free to submit a bug or send a pull request.
|
73
73
|
|
74
|
-
Fides currently only functions with PostgreSQL. Please feel free to contribute other adapters as desired.
|
74
|
+
Fides currently only functions with PostgreSQL and SQLite3. Please feel free to contribute other adapters as desired.
|
75
75
|
|
76
76
|
## Contributing
|
77
77
|
|
data/lib/fides/postgresql.rb
CHANGED
@@ -3,7 +3,19 @@ module Fides
|
|
3
3
|
class Postgresql
|
4
4
|
include SqlWriter
|
5
5
|
|
6
|
-
def self.
|
6
|
+
def self.executable_add_statements(interface_name, models, polymorphic_model)
|
7
|
+
sql = create_and_update_constraint_sql(interface_name, models, polymorphic_model)
|
8
|
+
sql << delete_constraint_sql(interface_name, models, polymorphic_model)
|
9
|
+
return [sql]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.executable_remove_statements(interface_name)
|
13
|
+
[drop_constraints_sql(interface_name)]
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def self.create_and_update_constraint_sql(interface_name, models, polymorphic_model)
|
7
19
|
|
8
20
|
sql = "DROP FUNCTION IF EXISTS check_#{interface_name}_create_integrity() CASCADE;"
|
9
21
|
|
@@ -34,12 +46,13 @@ module Fides
|
|
34
46
|
CREATE TRIGGER check_#{interface_name}_create_integrity_trigger
|
35
47
|
BEFORE INSERT OR UPDATE ON #{polymorphic_model.constantize.table_name}
|
36
48
|
FOR EACH ROW EXECUTE PROCEDURE check_#{interface_name}_create_integrity();
|
49
|
+
|
37
50
|
}
|
38
51
|
|
39
52
|
return strip_non_essential_spaces(sql)
|
40
53
|
end
|
41
54
|
|
42
|
-
def self.
|
55
|
+
def self.delete_constraint_sql(interface_name, models, polymorphic_model)
|
43
56
|
polymorphic_model_table_name = polymorphic_model.constantize.table_name
|
44
57
|
|
45
58
|
sql = ""
|
@@ -82,7 +95,7 @@ module Fides
|
|
82
95
|
return strip_non_essential_spaces(sql)
|
83
96
|
end
|
84
97
|
|
85
|
-
def self.
|
98
|
+
def self.drop_constraints_sql(interface_name)
|
86
99
|
sql = %{
|
87
100
|
DROP FUNCTION IF EXISTS check_#{interface_name}_create_integrity() CASCADE;
|
88
101
|
DROP FUNCTION IF EXISTS check_#{interface_name}_delete_integrity() CASCADE;
|
data/lib/fides/sqlite3.rb
CHANGED
@@ -5,12 +5,92 @@ module Fides
|
|
5
5
|
class Sqlite3
|
6
6
|
include SqlWriter
|
7
7
|
|
8
|
-
def self.
|
9
|
-
|
8
|
+
def self.executable_add_statements(interface_name, models, polymorphic_model)
|
9
|
+
statements = []
|
10
|
+
statements << drop_constraint_sql(interface_name, "create")
|
11
|
+
statements << create_constraint_sql(interface_name, models, polymorphic_model)
|
12
|
+
models.each do |model|
|
13
|
+
statements << drop_constraint_sql(model.constantize.table_name, "delete")
|
14
|
+
statements << delete_constraint_sql(interface_name, model, polymorphic_model)
|
15
|
+
end
|
16
|
+
statements << drop_constraint_sql(interface_name, "update")
|
17
|
+
statements << update_constraint_sql(interface_name, models, polymorphic_model)
|
18
|
+
return statements
|
10
19
|
end
|
11
20
|
|
12
|
-
def self.
|
13
|
-
|
21
|
+
def self.executable_remove_statements(interface_name)
|
22
|
+
statements = []
|
23
|
+
statements << drop_constraint_sql(interface_name, "create")
|
24
|
+
statements << drop_constraint_sql(interface_name, "delete")
|
25
|
+
return statements
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def self.drop_constraint_sql(name, drop_type)
|
31
|
+
strip_non_essential_spaces "DROP TRIGGER IF EXISTS check_#{name}_#{drop_type}_integrity;"
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.create_constraint_sql(interface_name, models, polymorphic_model)
|
35
|
+
sql = %{
|
36
|
+
|
37
|
+
CREATE TRIGGER check_#{interface_name}_create_integrity
|
38
|
+
BEFORE INSERT ON #{polymorphic_model.constantize.table_name}
|
39
|
+
BEGIN
|
40
|
+
SELECT CASE
|
41
|
+
}
|
42
|
+
|
43
|
+
models.each do |model|
|
44
|
+
sql << %{
|
45
|
+
WHEN ((NEW.#{interface_name}_type = '#{model}') AND (SELECT id
|
46
|
+
FROM #{model.constantize.table_name} WHERE id = NEW.#{interface_name}_id) ISNULL)
|
47
|
+
THEN RAISE(ABORT, 'There is no #{model} with that id.')
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
sql << "END; END;"
|
52
|
+
|
53
|
+
return strip_non_essential_spaces(sql)
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.update_constraint_sql(interface_name, models, polymorphic_model)
|
57
|
+
sql = %{
|
58
|
+
|
59
|
+
CREATE TRIGGER check_#{interface_name}_update_integrity
|
60
|
+
BEFORE UPDATE ON #{polymorphic_model.constantize.table_name}
|
61
|
+
BEGIN
|
62
|
+
SELECT CASE
|
63
|
+
}
|
64
|
+
|
65
|
+
models.each do |model|
|
66
|
+
sql << %{
|
67
|
+
WHEN ((NEW.#{interface_name}_type = '#{model}') AND (SELECT id
|
68
|
+
FROM #{model.constantize.table_name} WHERE id = NEW.#{interface_name}_id) ISNULL)
|
69
|
+
THEN RAISE(ABORT, 'There is no #{model} with that id.')
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
sql << "END; END;"
|
74
|
+
|
75
|
+
return strip_non_essential_spaces(sql)
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.delete_constraint_sql(interface_name, associated_model, polymorphic_model)
|
79
|
+
sql = %{
|
80
|
+
|
81
|
+
CREATE TRIGGER check_#{associated_model.constantize.table_name}_delete_integrity
|
82
|
+
BEFORE DELETE ON #{associated_model.constantize.table_name}
|
83
|
+
BEGIN
|
84
|
+
SELECT CASE
|
85
|
+
WHEN ((SELECT id FROM #{polymorphic_model.constantize.table_name}
|
86
|
+
WHERE #{interface_name}_type = '#{associated_model}' AND #{interface_name}_id = OLD.id) NOTNULL) THEN
|
87
|
+
RAISE(ABORT, 'There are records in the #{polymorphic_model.constantize.table_name} table that refer to the #{associated_model.constantize.table_name} record that is attempting to be deleted. Delete the dependent records in the #{polymorphic_model.constantize.table_name} table first.')
|
88
|
+
END;
|
89
|
+
END;
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
return strip_non_essential_spaces(sql)
|
14
94
|
end
|
15
95
|
|
16
96
|
end
|
data/lib/fides/version.rb
CHANGED
data/lib/fides.rb
CHANGED
@@ -10,7 +10,7 @@ require 'fides/database_adapter_error'
|
|
10
10
|
|
11
11
|
module Fides
|
12
12
|
|
13
|
-
SUPPORTED_ADAPTERS = ["postgresql"]
|
13
|
+
SUPPORTED_ADAPTERS = ["postgresql", "sqlite3"]
|
14
14
|
|
15
15
|
extend ActiveSupport::Concern
|
16
16
|
|
@@ -24,10 +24,9 @@ module Fides
|
|
24
24
|
|
25
25
|
fides_sql_generator = get_sql_generator_class
|
26
26
|
|
27
|
-
|
28
|
-
sql << fides_sql_generator.get_delete_function_sql(interface, associated_models, polymorphic_model)
|
27
|
+
execution_statements = fides_sql_generator.executable_add_statements(interface, associated_models, polymorphic_model)
|
29
28
|
|
30
|
-
execute
|
29
|
+
execution_statements.each { |statement| execute statement }
|
31
30
|
end
|
32
31
|
|
33
32
|
def remove_polymorphic_triggers(opts)
|
@@ -36,9 +35,9 @@ module Fides
|
|
36
35
|
polymorphic_model = opts[:polymorphic_model]
|
37
36
|
interface = opts.has_key?(:interface_name) ? opts[:interface_name] : interface_name(polymorphic_model)
|
38
37
|
|
39
|
-
|
38
|
+
execution_statements = get_sql_generator_class.executable_remove_statements(interface)
|
40
39
|
|
41
|
-
execute
|
40
|
+
execution_statements.each { |statement| execute statement }
|
42
41
|
end
|
43
42
|
|
44
43
|
private
|
@@ -54,7 +53,6 @@ module Fides
|
|
54
53
|
model_name.constantize.reflect_on_all_associations.select { |r| r if r.options[:polymorphic] }.first.name
|
55
54
|
end
|
56
55
|
|
57
|
-
|
58
56
|
end
|
59
57
|
|
60
58
|
class ActiveRecord::Migration
|
@@ -4,75 +4,76 @@ describe Fides::Postgresql do
|
|
4
4
|
|
5
5
|
let(:subject) { Fides::Postgresql }
|
6
6
|
|
7
|
-
it 'responds to #
|
8
|
-
assert_respond_to subject, :
|
7
|
+
it 'responds to #executable_add_statements' do
|
8
|
+
assert_respond_to subject, :executable_add_statements
|
9
9
|
end
|
10
10
|
|
11
|
-
it 'responds to #
|
12
|
-
assert_respond_to subject, :
|
11
|
+
it 'responds to #executable_remove_statements' do
|
12
|
+
assert_respond_to subject, :executable_remove_statements
|
13
13
|
end
|
14
14
|
|
15
|
-
it 'returns an expected SQL string' do
|
16
|
-
sql = subject.
|
17
|
-
assert_equal subject.strip_non_essential_spaces(
|
15
|
+
it 'returns an expected add constraints SQL string' do
|
16
|
+
sql = subject.executable_add_statements("imageable", ["Product", "Employee"], "Picture")[0]
|
17
|
+
assert_equal subject.strip_non_essential_spaces(add_constraints_sql), sql
|
18
18
|
end
|
19
19
|
|
20
|
-
it 'returns an expected SQL string' do
|
21
|
-
sql = subject.
|
22
|
-
assert_equal subject.strip_non_essential_spaces(
|
20
|
+
it 'returns an expected drop constraints SQL string' do
|
21
|
+
sql = subject.executable_remove_statements("imageable")[0]
|
22
|
+
assert_equal subject.strip_non_essential_spaces(drop_constraing_sql), sql
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
CREATE TRIGGER check_employees_delete_integrity_trigger
|
73
|
-
BEFORE DELETE ON employees
|
74
|
-
FOR EACH ROW EXECUTE PROCEDURE check_imageable_delete_integrity();
|
25
|
+
let(:add_constraints_sql) do %{
|
26
|
+
|
27
|
+
DROP FUNCTION IF EXISTS check_imageable_create_integrity() CASCADE;
|
28
|
+
|
29
|
+
CREATE FUNCTION check_imageable_create_integrity() RETURNS TRIGGER AS '
|
30
|
+
BEGIN
|
31
|
+
IF NEW.imageable_type = ''Product'' AND EXISTS (
|
32
|
+
SELECT id FROM products WHERE id = NEW.imageable_id) THEN
|
33
|
+
RETURN NEW;
|
34
|
+
ELSEIF NEW.imageable_type = ''Employee'' AND EXISTS (
|
35
|
+
SELECT id FROM employees WHERE id = NEW.imageable_id) THEN
|
36
|
+
RETURN NEW;
|
37
|
+
ELSE
|
38
|
+
RAISE EXCEPTION ''No % model with id %.'', NEW.imageable_type, NEW.imageable_id;
|
39
|
+
RETURN NULL;
|
40
|
+
END IF;
|
41
|
+
END'
|
42
|
+
LANGUAGE plpgsql;
|
43
|
+
|
44
|
+
CREATE TRIGGER check_imageable_create_integrity_trigger
|
45
|
+
BEFORE INSERT OR UPDATE ON pictures
|
46
|
+
FOR EACH ROW EXECUTE PROCEDURE check_imageable_create_integrity();CREATE FUNCTION check_imageable_delete_integrity() RETURNS TRIGGER AS '
|
47
|
+
BEGIN
|
48
|
+
IF TG_TABLE_NAME = ''products'' AND EXISTS (
|
49
|
+
SELECT id FROM pictures
|
50
|
+
WHERE imageable_type = ''Product'' AND imageable_id = OLD.id) THEN
|
51
|
+
RAISE EXCEPTION ''There are records in pictures that refer to %. You must delete those records first.'', OLD;
|
52
|
+
ELSEIF TG_TABLE_NAME = ''employees'' AND EXISTS (
|
53
|
+
SELECT id FROM pictures
|
54
|
+
WHERE imageable_type = ''Employee'' AND imageable_id = OLD.id) THEN
|
55
|
+
RAISE EXCEPTION ''There are records in pictures that refer to %. You must delete those records first.'', OLD;
|
56
|
+
ELSE
|
57
|
+
RETURN NULL;
|
58
|
+
END IF;
|
59
|
+
END'
|
60
|
+
LANGUAGE plpgsql;
|
61
|
+
|
62
|
+
CREATE TRIGGER check_products_delete_integrity_trigger
|
63
|
+
BEFORE DELETE ON products
|
64
|
+
FOR EACH ROW EXECUTE PROCEDURE check_imageable_delete_integrity();
|
65
|
+
|
66
|
+
CREATE TRIGGER check_employees_delete_integrity_trigger
|
67
|
+
BEFORE DELETE ON employees
|
68
|
+
FOR EACH ROW EXECUTE PROCEDURE check_imageable_delete_integrity();
|
69
|
+
|
70
|
+
}
|
71
|
+
end
|
75
72
|
|
76
|
-
|
73
|
+
let(:drop_constraing_sql) do %{
|
74
|
+
DROP FUNCTION IF EXISTS check_imageable_create_integrity() CASCADE;
|
75
|
+
DROP FUNCTION IF EXISTS check_imageable_delete_integrity() CASCADE;
|
76
|
+
}
|
77
|
+
end
|
77
78
|
|
78
79
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Fides::SqlWriter do
|
4
|
+
|
5
|
+
before do
|
6
|
+
class MyTestClass
|
7
|
+
include Fides::SqlWriter
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#strip_non_essential_spaces" do
|
12
|
+
it 'removes newline characters' do
|
13
|
+
dirty_string = "asdjfkals;dfj\n\n\nasdfjkl;asdf\n\n\nasjfklas;fdj"
|
14
|
+
clean_string = "asdjfkals;dfj asdfjkl;asdf asjfklas;fdj"
|
15
|
+
assert_equal clean_string, MyTestClass.strip_non_essential_spaces(dirty_string)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'turns multiple spaces into 1 space' do
|
19
|
+
dirty_string = "a sdjfkals;dfj asdfjkl;a sdfasjfklas; fdj"
|
20
|
+
clean_string = "a sdjfkals;dfj asdfjkl;a sdfasjfklas; fdj"
|
21
|
+
assert_equal clean_string, MyTestClass.strip_non_essential_spaces(dirty_string)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'removes tabs' do
|
25
|
+
dirty_string = "hel\t\tlowor\t\t\t\tld\t"
|
26
|
+
clean_string = "hel lowor ld"
|
27
|
+
assert_equal clean_string, MyTestClass.strip_non_essential_spaces(dirty_string)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'trips the string' do
|
31
|
+
dirty_string = " abc 123 "
|
32
|
+
clean_string = "abc 123"
|
33
|
+
assert_equal clean_string, MyTestClass.strip_non_essential_spaces(dirty_string)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Fides::Sqlite3 do
|
4
|
+
|
5
|
+
let(:subject) { Fides::Sqlite3 }
|
6
|
+
|
7
|
+
it 'responds to #executable_add_statements' do
|
8
|
+
assert_respond_to subject, :executable_add_statements
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'responds to #executable_remove_statements' do
|
12
|
+
assert_respond_to subject, :executable_remove_statements
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'returns expected create constrains statements' do
|
16
|
+
statements = subject.executable_add_statements("imageable", ["Product", "Employee"], "Picture")
|
17
|
+
statements.each_with_index do |statement, index|
|
18
|
+
assert_equal subject.strip_non_essential_spaces( send("add_sql#{index + 1}") ), statement
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns expected drop constrains statements' do
|
23
|
+
sql1 = subject.executable_remove_statements("imageable")[0]
|
24
|
+
sql2 = subject.executable_remove_statements("imageable")[1]
|
25
|
+
assert_equal subject.strip_non_essential_spaces(drop_sql1), sql1
|
26
|
+
assert_equal subject.strip_non_essential_spaces(drop_sql2), sql2
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:add_sql1) do %{
|
30
|
+
DROP TRIGGER IF EXISTS check_imageable_create_integrity;
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:add_sql2) do %{
|
35
|
+
CREATE TRIGGER check_imageable_create_integrity
|
36
|
+
BEFORE INSERT ON pictures
|
37
|
+
BEGIN
|
38
|
+
SELECT CASE
|
39
|
+
WHEN ((NEW.imageable_type = 'Product') AND (SELECT id FROM products WHERE id = NEW.imageable_id) ISNULL) THEN RAISE(ABORT, 'There is no Product with that id.')
|
40
|
+
WHEN ((NEW.imageable_type = 'Employee') AND (SELECT id FROM employees WHERE id = NEW.imageable_id) ISNULL) THEN RAISE(ABORT, 'There is no Employee with that id.')
|
41
|
+
END;
|
42
|
+
END;
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
let(:add_sql3) do %{
|
47
|
+
DROP TRIGGER IF EXISTS check_products_delete_integrity;
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
let(:add_sql4) do %{
|
52
|
+
CREATE TRIGGER check_products_delete_integrity
|
53
|
+
BEFORE DELETE ON products
|
54
|
+
BEGIN
|
55
|
+
SELECT CASE
|
56
|
+
WHEN ((SELECT id FROM pictures WHERE imageable_type = 'Product' AND imageable_id = OLD.id) NOTNULL) THEN
|
57
|
+
RAISE(ABORT, 'There are records in the pictures table that refer to the products record that is attempting to be deleted. Delete the dependent records in the pictures table first.')
|
58
|
+
END;
|
59
|
+
END;
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
let(:add_sql5) do %{
|
64
|
+
DROP TRIGGER IF EXISTS check_employees_delete_integrity;
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
let(:add_sql6) do %{
|
69
|
+
CREATE TRIGGER check_employees_delete_integrity
|
70
|
+
BEFORE DELETE ON employees
|
71
|
+
BEGIN
|
72
|
+
SELECT CASE
|
73
|
+
WHEN ((SELECT id FROM pictures WHERE imageable_type = 'Employee' AND imageable_id = OLD.id) NOTNULL) THEN
|
74
|
+
RAISE(ABORT, 'There are records in the pictures table that refer to the employees record that is attempting to be deleted. Delete the dependent records in the pictures table first.')
|
75
|
+
END;
|
76
|
+
END;
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
let(:add_sql7) do %{
|
81
|
+
DROP TRIGGER IF EXISTS check_imageable_update_integrity;
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
let(:add_sql8) do %{
|
86
|
+
CREATE TRIGGER check_imageable_update_integrity
|
87
|
+
BEFORE UPDATE ON pictures
|
88
|
+
BEGIN
|
89
|
+
SELECT CASE
|
90
|
+
WHEN ((NEW.imageable_type = 'Product') AND (SELECT id FROM products WHERE id = NEW.imageable_id) ISNULL) THEN RAISE(ABORT, 'There is no Product with that id.')
|
91
|
+
WHEN ((NEW.imageable_type = 'Employee') AND (SELECT id FROM employees WHERE id = NEW.imageable_id) ISNULL) THEN RAISE(ABORT, 'There is no Employee with that id.')
|
92
|
+
END;
|
93
|
+
END;
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
let(:drop_sql1) do %{
|
98
|
+
DROP TRIGGER IF EXISTS check_imageable_create_integrity;
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
102
|
+
let(:drop_sql2) do %{
|
103
|
+
DROP TRIGGER IF EXISTS check_imageable_delete_integrity;
|
104
|
+
}
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fides
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Kraft
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -128,10 +128,13 @@ files:
|
|
128
128
|
- lib/fides/sql_writer.rb
|
129
129
|
- lib/fides/sqlite3.rb
|
130
130
|
- lib/fides/version.rb
|
131
|
-
- test/lib/fides/database_adapter_test.rb
|
132
131
|
- test/lib/fides/postgresql_test.rb
|
132
|
+
- test/lib/fides/sql_writer_test.rb
|
133
|
+
- test/lib/fides/sqlite3_test.rb
|
133
134
|
- test/lib/fides/version_test.rb
|
134
135
|
- test/lib/fides_test.rb
|
136
|
+
- test/lib/integration/postgresql_db_test.rb
|
137
|
+
- test/lib/integration/sqlite3_db_test.rb
|
135
138
|
- test/test_helper.rb
|
136
139
|
homepage: https://github.com/mkraft/fides
|
137
140
|
licenses:
|
@@ -159,8 +162,11 @@ specification_version: 4
|
|
159
162
|
summary: Creates SQL triggers from Rails migrations to enforce the integrity of polymorphic
|
160
163
|
associations at the database level.
|
161
164
|
test_files:
|
162
|
-
- test/lib/fides/database_adapter_test.rb
|
163
165
|
- test/lib/fides/postgresql_test.rb
|
166
|
+
- test/lib/fides/sql_writer_test.rb
|
167
|
+
- test/lib/fides/sqlite3_test.rb
|
164
168
|
- test/lib/fides/version_test.rb
|
165
169
|
- test/lib/fides_test.rb
|
170
|
+
- test/lib/integration/postgresql_db_test.rb
|
171
|
+
- test/lib/integration/sqlite3_db_test.rb
|
166
172
|
- test/test_helper.rb
|