|
11 | 11 | $$ LANGUAGE plpgsql; |
12 | 12 | EOS |
13 | 13 | connection.create_function :my_function, sql_definition: sql_definition |
14 | | - connection.create_table :my_table |
| 14 | + connection.create_table :my_table, if_not_exists: true |
15 | 15 | stream = StringIO.new |
16 | 16 | output = stream.string |
17 | 17 |
|
|
33 | 33 | $$ LANGUAGE plpgsql; |
34 | 34 | EOS |
35 | 35 | connection.create_function :my_function, sql_definition: sql_definition |
36 | | - connection.create_table :my_table |
| 36 | + connection.create_table :my_table, if_not_exists: true |
37 | 37 | stream = StringIO.new |
38 | 38 | output = stream.string |
39 | 39 |
|
|
48 | 48 |
|
49 | 49 | it "does not dump a create_function for aggregates in the database" do |
50 | 50 | sql_definition = <<~EOS |
51 | | - CREATE OR REPLACE FUNCTION test(text, text) |
| 51 | + CREATE OR REPLACE FUNCTION test_with_args(text, text) |
52 | 52 | RETURNS text AS $$ |
53 | 53 | BEGIN |
54 | 54 | RETURN 'test'; |
|
57 | 57 | EOS |
58 | 58 |
|
59 | 59 | aggregate_sql_definition = <<~EOS |
60 | | - CREATE AGGREGATE aggregate_test(text) |
| 60 | + CREATE OR REPLACE AGGREGATE aggregate_test(text) |
61 | 61 | ( |
62 | | - sfunc = test, |
| 62 | + sfunc = test_with_args, |
63 | 63 | stype = text |
64 | 64 | ); |
65 | 65 | EOS |
|
71 | 71 | dump(connection: connection, stream: stream) |
72 | 72 |
|
73 | 73 | output = stream.string |
74 | | - expect(output).to include("create_function :test, sql_definition: <<-'SQL'") |
| 74 | + expect(output).to include("create_function :test_with_args, sql_definition: <<-'SQL'") |
75 | 75 | expect(output).to include("RETURN 'test';") |
76 | 76 | expect(output).not_to include("aggregate_test") |
77 | 77 | end |
78 | 78 |
|
79 | 79 | it "dumps a create_trigger for a trigger in the database" do |
80 | 80 | connection.execute <<~EOS |
81 | | - CREATE TABLE users ( |
| 81 | + CREATE TABLE IF NOT EXISTS users ( |
82 | 82 | id int PRIMARY KEY, |
83 | 83 | name varchar(256), |
84 | 84 | upper_name varchar(256) |
|
94 | 94 | $$ LANGUAGE plpgsql; |
95 | 95 | EOS |
96 | 96 | sql_definition = <<~EOS |
97 | | - CREATE TRIGGER uppercase_users_name |
| 97 | + CREATE OR REPLACE TRIGGER uppercase_users_name |
98 | 98 | BEFORE INSERT ON users |
99 | 99 | FOR EACH ROW |
100 | 100 | EXECUTE FUNCTION uppercase_users_name(); |
|
0 commit comments