2008-04-21 06:00:01 -04:00
|
|
|
ActiveRecord::Schema.define do
|
|
|
|
|
2016-08-06 12:26:20 -04:00
|
|
|
enable_extension!("uuid-ossp", ActiveRecord::Base.connection)
|
2015-05-03 08:13:13 -04:00
|
|
|
|
|
|
|
create_table :uuid_parents, id: :uuid, force: true do |t|
|
|
|
|
t.string :name
|
|
|
|
end
|
|
|
|
|
|
|
|
create_table :uuid_children, id: :uuid, force: true do |t|
|
|
|
|
t.string :name
|
|
|
|
t.uuid :uuid_parent_id
|
|
|
|
end
|
|
|
|
|
2015-05-03 07:49:45 -04:00
|
|
|
create_table :defaults, force: true do |t|
|
2016-08-06 12:26:20 -04:00
|
|
|
t.date :modified_date, default: -> { "CURRENT_DATE" }
|
|
|
|
t.date :modified_date_function, default: -> { "now()" }
|
|
|
|
t.date :fixed_date, default: "2004-01-01"
|
|
|
|
t.datetime :modified_time, default: -> { "CURRENT_TIMESTAMP" }
|
|
|
|
t.datetime :modified_time_function, default: -> { "now()" }
|
|
|
|
t.datetime :fixed_time, default: "2004-01-01 00:00:00.000000-00"
|
|
|
|
t.column :char1, "char(1)", default: "Y"
|
|
|
|
t.string :char2, limit: 50, default: "a varchar field"
|
|
|
|
t.text :char3, default: "a text field"
|
|
|
|
t.bigint :bigint_default, default: -> { "0::bigint" }
|
2015-05-03 07:49:45 -04:00
|
|
|
t.text :multiline_default, default: '--- []
|
|
|
|
|
|
|
|
'
|
|
|
|
end
|
|
|
|
|
|
|
|
%w(postgresql_times postgresql_oids postgresql_timestamp_with_zones
|
2014-12-02 05:32:54 -05:00
|
|
|
postgresql_partitioned_table postgresql_partitioned_table_parent).each do |table_name|
|
2015-02-18 06:47:01 -05:00
|
|
|
drop_table table_name, if_exists: true
|
2008-04-21 06:00:01 -04:00
|
|
|
end
|
|
|
|
|
2016-08-06 12:26:20 -04:00
|
|
|
execute "DROP SEQUENCE IF EXISTS companies_nonstd_seq CASCADE"
|
|
|
|
execute "CREATE SEQUENCE companies_nonstd_seq START 101 OWNED BY companies.id"
|
2008-04-21 06:00:01 -04:00
|
|
|
execute "ALTER TABLE companies ALTER COLUMN id SET DEFAULT nextval('companies_nonstd_seq')"
|
2016-08-06 12:26:20 -04:00
|
|
|
execute "DROP SEQUENCE IF EXISTS companies_id_seq"
|
2008-04-21 06:00:01 -04:00
|
|
|
|
2016-08-06 12:26:20 -04:00
|
|
|
execute "DROP FUNCTION IF EXISTS partitioned_insert_trigger()"
|
2012-03-31 16:38:11 -04:00
|
|
|
|
2008-04-21 06:00:01 -04:00
|
|
|
%w(accounts_id_seq developers_id_seq projects_id_seq topics_id_seq customers_id_seq orders_id_seq).each do |seq_name|
|
|
|
|
execute "SELECT setval('#{seq_name}', 100)"
|
|
|
|
end
|
|
|
|
|
|
|
|
execute <<_SQL
|
|
|
|
CREATE TABLE postgresql_times (
|
|
|
|
id SERIAL PRIMARY KEY,
|
2012-09-05 07:06:28 -04:00
|
|
|
time_interval INTERVAL,
|
|
|
|
scaled_time_interval INTERVAL(6)
|
2008-04-21 06:00:01 -04:00
|
|
|
);
|
|
|
|
_SQL
|
|
|
|
|
|
|
|
execute <<_SQL
|
|
|
|
CREATE TABLE postgresql_oids (
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
obj_id OID
|
|
|
|
);
|
|
|
|
_SQL
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2010-01-23 21:16:29 -05:00
|
|
|
execute <<_SQL
|
|
|
|
CREATE TABLE postgresql_timestamp_with_zones (
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
time TIMESTAMP WITH TIME ZONE
|
|
|
|
);
|
|
|
|
_SQL
|
2009-08-09 04:56:25 -04:00
|
|
|
|
2012-11-28 08:47:48 -05:00
|
|
|
begin
|
2012-04-27 22:53:07 -04:00
|
|
|
execute <<_SQL
|
|
|
|
CREATE TABLE postgresql_partitioned_table_parent (
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
number integer
|
|
|
|
);
|
|
|
|
CREATE TABLE postgresql_partitioned_table ( )
|
|
|
|
INHERITS (postgresql_partitioned_table_parent);
|
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION partitioned_insert_trigger()
|
|
|
|
RETURNS TRIGGER AS $$
|
|
|
|
BEGIN
|
|
|
|
INSERT INTO postgresql_partitioned_table VALUES (NEW.*);
|
|
|
|
RETURN NULL;
|
|
|
|
END;
|
|
|
|
$$
|
|
|
|
LANGUAGE plpgsql;
|
|
|
|
|
|
|
|
CREATE TRIGGER insert_partitioning_trigger
|
|
|
|
BEFORE INSERT ON postgresql_partitioned_table_parent
|
|
|
|
FOR EACH ROW EXECUTE PROCEDURE partitioned_insert_trigger();
|
2012-03-31 16:38:11 -04:00
|
|
|
_SQL
|
2012-11-28 08:47:48 -05:00
|
|
|
rescue ActiveRecord::StatementInvalid => e
|
2016-07-23 14:01:56 -04:00
|
|
|
if e.message.include?('language "plpgsql" does not exist')
|
2012-11-28 08:47:48 -05:00
|
|
|
execute "CREATE LANGUAGE 'plpgsql';"
|
|
|
|
retry
|
|
|
|
else
|
|
|
|
raise e
|
|
|
|
end
|
2012-04-27 22:53:07 -04:00
|
|
|
end
|
2012-03-31 16:38:11 -04:00
|
|
|
|
2012-11-28 08:11:11 -05:00
|
|
|
# This table is to verify if the :limit option is being ignored for text and binary columns
|
2012-11-19 22:38:19 -05:00
|
|
|
create_table :limitless_fields, force: true do |t|
|
|
|
|
t.binary :binary, limit: 100_000
|
|
|
|
t.text :text, limit: 100_000
|
|
|
|
end
|
2015-03-21 18:08:55 -04:00
|
|
|
|
|
|
|
create_table :bigint_array, force: true do |t|
|
|
|
|
t.integer :big_int_data_points, limit: 8, array: true
|
2015-06-11 18:48:23 -04:00
|
|
|
t.decimal :decimal_array_default, array: true, default: [1.23, 3.45]
|
2015-03-21 18:08:55 -04:00
|
|
|
end
|
2016-02-11 22:58:18 -05:00
|
|
|
|
|
|
|
create_table :uuid_items, force: true, id: false do |t|
|
|
|
|
t.uuid :uuid, primary_key: true
|
|
|
|
t.string :title
|
|
|
|
end
|
2009-08-09 04:56:25 -04:00
|
|
|
end
|