|
57 | 57 | id INT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY |
58 | 58 | ) |
59 | 59 | SQL |
| 60 | + |
| 61 | + drop_table "cpk_postgresql_identity_table", if_exists: true |
| 62 | + execute <<~SQL |
| 63 | + create table cpk_postgresql_identity_table ( |
| 64 | + another_id INT NOT NULL, |
| 65 | + id INT NOT NULL GENERATED BY DEFAULT AS IDENTITY, |
| 66 | + CONSTRAINT cpk_postgresql_identity_table_pkey PRIMARY KEY (another_id, id) |
| 67 | + ) |
| 68 | + SQL |
60 | 69 | end |
61 | 70 |
|
62 | 71 | create_table :postgresql_times, force: true do |t| |
|
77 | 86 | execute "ALTER TABLE companies ALTER COLUMN id SET DEFAULT nextval('companies_nonstd_seq')" |
78 | 87 | execute "DROP SEQUENCE IF EXISTS companies_id_seq" |
79 | 88 |
|
80 | | - # Stored procedures are not supported in CockroachDB. |
81 | | - # See https://github.com/cockroachdb/cockroach/issues/17511. |
82 | | - # execute "DROP FUNCTION IF EXISTS partitioned_insert_trigger()" |
| 89 | + execute "DROP FUNCTION IF EXISTS partitioned_insert_trigger()" |
83 | 90 |
|
84 | 91 | # CockroachDB uses unique_rowid() for primary keys by default instead of |
85 | 92 | # sequences. Therefore, there aren't any sequences to update here. |
|
95 | 102 | ); |
96 | 103 | _SQL |
97 | 104 |
|
98 | | -# Since stored procedures are not supported in CockroachDB, it won't be possible |
99 | | -# to do trigger based partitioning. |
100 | | -# See https://github.com/cockroachdb/cockroach/issues/17511. |
101 | | -# begin |
102 | | -# execute <<_SQL |
103 | | -# CREATE TABLE postgresql_partitioned_table_parent ( |
104 | | -# id SERIAL PRIMARY KEY, |
105 | | -# number integer |
106 | | -# ); |
107 | | -# CREATE TABLE postgresql_partitioned_table ( ) |
108 | | -# INHERITS (postgresql_partitioned_table_parent); |
109 | | -# |
110 | | -# CREATE OR REPLACE FUNCTION partitioned_insert_trigger() |
111 | | -# RETURNS TRIGGER AS $$ |
112 | | -# BEGIN |
113 | | -# INSERT INTO postgresql_partitioned_table VALUES (NEW.*); |
114 | | -# RETURN NULL; |
115 | | -# END; |
116 | | -# $$ |
117 | | -# LANGUAGE plpgsql; |
118 | | -# |
119 | | -# CREATE TRIGGER insert_partitioning_trigger |
120 | | -# BEFORE INSERT ON postgresql_partitioned_table_parent |
121 | | -# FOR EACH ROW EXECUTE PROCEDURE partitioned_insert_trigger(); |
122 | | -# _SQL |
123 | | -# rescue ActiveRecord::StatementInvalid => e |
124 | | -# if e.message.include?('language "plpgsql" does not exist') |
125 | | -# execute "CREATE LANGUAGE 'plpgsql';" |
126 | | -# retry |
127 | | -# else |
128 | | -# raise e |
129 | | -# end |
130 | | -# end |
| 105 | + begin |
| 106 | + execute <<_SQL |
| 107 | + CREATE TABLE postgresql_partitioned_table_parent ( |
| 108 | + id SERIAL PRIMARY KEY, |
| 109 | + number integer |
| 110 | + ); |
| 111 | + CREATE TABLE postgresql_partitioned_table ( ) |
| 112 | + INHERITS (postgresql_partitioned_table_parent); |
| 113 | +
|
| 114 | + CREATE OR REPLACE FUNCTION partitioned_insert_trigger() |
| 115 | + RETURNS TRIGGER AS $$ |
| 116 | + BEGIN |
| 117 | + INSERT INTO postgresql_partitioned_table VALUES (NEW.*); |
| 118 | + RETURN NULL; |
| 119 | + END; |
| 120 | + $$ |
| 121 | + LANGUAGE plpgsql; |
| 122 | +
|
| 123 | + CREATE TRIGGER insert_partitioning_trigger |
| 124 | + BEFORE INSERT ON postgresql_partitioned_table_parent |
| 125 | + FOR EACH ROW EXECUTE PROCEDURE partitioned_insert_trigger(); |
| 126 | +_SQL |
| 127 | + rescue ActiveRecord::StatementInvalid => e |
| 128 | + if e.message.include?('language "plpgsql" does not exist') |
| 129 | + execute "CREATE LANGUAGE 'plpgsql';" |
| 130 | + retry |
| 131 | + else |
| 132 | + raise e |
| 133 | + end |
| 134 | + end |
131 | 135 |
|
132 | 136 | # This table is to verify if the :limit option is being ignored for text and binary columns |
133 | 137 | create_table :limitless_fields, force: true do |t| |
|
0 commit comments