2017-07-09 13:41:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2010-08-02 04:37:57 -04:00
|
|
|
ActiveRecord::Schema.define do
|
2020-04-24 13:56:53 -04:00
|
|
|
if supports_datetime_with_precision?
|
2015-05-04 06:01:24 -04:00
|
|
|
create_table :datetime_defaults, force: true do |t|
|
2016-08-06 12:26:20 -04:00
|
|
|
t.datetime :modified_datetime, default: -> { "CURRENT_TIMESTAMP" }
|
2018-07-03 03:17:40 -04:00
|
|
|
t.datetime :precise_datetime, precision: 6, default: -> { "CURRENT_TIMESTAMP(6)" }
|
2015-05-04 06:01:24 -04:00
|
|
|
end
|
|
|
|
|
2018-07-08 15:27:35 -04:00
|
|
|
create_table :timestamp_defaults, force: true do |t|
|
|
|
|
t.timestamp :nullable_timestamp
|
|
|
|
t.timestamp :modified_timestamp, default: -> { "CURRENT_TIMESTAMP" }
|
|
|
|
t.timestamp :precise_timestamp, precision: 6, default: -> { "CURRENT_TIMESTAMP(6)" }
|
|
|
|
end
|
2015-10-11 08:45:55 -04:00
|
|
|
end
|
|
|
|
|
2016-05-21 09:32:28 -04:00
|
|
|
create_table :defaults, force: true do |t|
|
|
|
|
t.date :fixed_date, default: "2004-01-01"
|
|
|
|
t.datetime :fixed_time, default: "2004-01-01 00:00:00"
|
|
|
|
t.column :char1, "char(1)", default: "Y"
|
|
|
|
t.string :char2, limit: 50, default: "a varchar field"
|
2018-10-24 21:11:31 -04:00
|
|
|
if supports_default_expression?
|
|
|
|
t.binary :uuid, limit: 36, default: -> { "(uuid())" }
|
|
|
|
end
|
2016-05-21 09:32:28 -04:00
|
|
|
end
|
|
|
|
|
2012-10-16 05:53:18 -04:00
|
|
|
create_table :binary_fields, force: true do |t|
|
|
|
|
t.binary :var_binary, limit: 255
|
|
|
|
t.binary :var_binary_large, limit: 4095
|
2019-01-25 08:01:07 -05:00
|
|
|
|
2015-09-13 03:24:38 -04:00
|
|
|
t.tinyblob :tiny_blob
|
|
|
|
t.blob :normal_blob
|
|
|
|
t.mediumblob :medium_blob
|
|
|
|
t.longblob :long_blob
|
|
|
|
t.tinytext :tiny_text
|
|
|
|
t.text :normal_text
|
|
|
|
t.mediumtext :medium_text
|
|
|
|
t.longtext :long_text
|
2010-08-02 04:37:57 -04:00
|
|
|
|
2019-01-25 08:01:07 -05:00
|
|
|
t.binary :tiny_blob_2, size: :tiny
|
|
|
|
t.binary :medium_blob_2, size: :medium
|
|
|
|
t.binary :long_blob_2, size: :long
|
|
|
|
t.text :tiny_text_2, size: :tiny
|
|
|
|
t.text :medium_text_2, size: :medium
|
|
|
|
t.text :long_text_2, size: :long
|
|
|
|
|
2015-09-13 03:24:38 -04:00
|
|
|
t.index :var_binary
|
|
|
|
end
|
2012-10-16 05:53:18 -04:00
|
|
|
|
2018-09-11 16:03:34 -04:00
|
|
|
create_table :key_tests, force: true do |t|
|
2013-03-27 00:30:11 -04:00
|
|
|
t.string :awesome
|
|
|
|
t.string :pizza
|
|
|
|
t.string :snacks
|
2016-08-06 12:26:20 -04:00
|
|
|
t.index :awesome, type: :fulltext, name: "index_key_tests_on_awesome"
|
|
|
|
t.index :pizza, using: :btree, name: "index_key_tests_on_pizza"
|
|
|
|
t.index :snacks, name: "index_key_tests_on_snack"
|
2013-03-27 00:30:11 -04:00
|
|
|
end
|
|
|
|
|
2014-11-09 23:53:27 -05:00
|
|
|
create_table :collation_tests, id: false, force: true do |t|
|
2018-09-20 14:54:39 -04:00
|
|
|
t.string :string_cs_column, limit: 1, collation: "utf8mb4_bin"
|
|
|
|
t.string :string_ci_column, limit: 1, collation: "utf8mb4_general_ci"
|
2016-02-20 21:28:11 -05:00
|
|
|
t.binary :binary_column, limit: 1
|
2014-11-09 23:53:27 -05:00
|
|
|
end
|
|
|
|
|
Use squiggly heredoc to strip odd indentation in the executed SQL
Before:
```
LOG: execute <unnamed>: SELECT t.oid, t.typname
FROM pg_type as t
WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'bool')
LOG: execute <unnamed>: SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
FROM pg_type as t
LEFT JOIN pg_range as r ON oid = rngtypid
WHERE
t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'text', 'varchar', 'char', 'name', 'bpchar', 'bool', 'bit', 'varbit', 'timestamptz', 'date', 'money', 'bytea', 'point', 'hstore', 'json', 'jsonb', 'cidr', 'inet', 'uuid', 'xml', 'tsvector', 'macaddr', 'citext', 'ltree', 'interval', 'path', 'line', 'polygon', 'circle', 'lseg', 'box', 'time', 'timestamp', 'numeric')
OR t.typtype IN ('r', 'e', 'd')
OR t.typinput::varchar = 'array_in'
OR t.typelem != 0
LOG: statement: SHOW TIME ZONE
LOG: statement: SELECT 1
LOG: execute <unnamed>: SELECT COUNT(*)
FROM pg_class c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view
AND c.relname = 'accounts'
AND n.nspname = ANY (current_schemas(false))
```
After:
```
LOG: execute <unnamed>: SELECT t.oid, t.typname
FROM pg_type as t
WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'bool')
LOG: execute <unnamed>: SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
FROM pg_type as t
LEFT JOIN pg_range as r ON oid = rngtypid
WHERE
t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'text', 'varchar', 'char', 'name', 'bpchar', 'bool', 'bit', 'varbit', 'timestamptz', 'date', 'money', 'bytea', 'point', 'hstore', 'json', 'jsonb', 'cidr', 'inet', 'uuid', 'xml', 'tsvector', 'macaddr', 'citext', 'ltree', 'interval', 'path', 'line', 'polygon', 'circle', 'lseg', 'box', 'time', 'timestamp', 'numeric')
OR t.typtype IN ('r', 'e', 'd')
OR t.typinput::varchar = 'array_in'
OR t.typelem != 0
LOG: statement: SHOW TIME ZONE
LOG: statement: SELECT 1
LOG: execute <unnamed>: SELECT COUNT(*)
FROM pg_class c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view
AND c.relname = 'accounts'
AND n.nspname = ANY (current_schemas(false))
```
2018-11-05 08:47:26 -05:00
|
|
|
execute "DROP PROCEDURE IF EXISTS ten"
|
2015-10-11 03:44:49 -04:00
|
|
|
|
Use squiggly heredoc to strip odd indentation in the executed SQL
Before:
```
LOG: execute <unnamed>: SELECT t.oid, t.typname
FROM pg_type as t
WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'bool')
LOG: execute <unnamed>: SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
FROM pg_type as t
LEFT JOIN pg_range as r ON oid = rngtypid
WHERE
t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'text', 'varchar', 'char', 'name', 'bpchar', 'bool', 'bit', 'varbit', 'timestamptz', 'date', 'money', 'bytea', 'point', 'hstore', 'json', 'jsonb', 'cidr', 'inet', 'uuid', 'xml', 'tsvector', 'macaddr', 'citext', 'ltree', 'interval', 'path', 'line', 'polygon', 'circle', 'lseg', 'box', 'time', 'timestamp', 'numeric')
OR t.typtype IN ('r', 'e', 'd')
OR t.typinput::varchar = 'array_in'
OR t.typelem != 0
LOG: statement: SHOW TIME ZONE
LOG: statement: SELECT 1
LOG: execute <unnamed>: SELECT COUNT(*)
FROM pg_class c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view
AND c.relname = 'accounts'
AND n.nspname = ANY (current_schemas(false))
```
After:
```
LOG: execute <unnamed>: SELECT t.oid, t.typname
FROM pg_type as t
WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'bool')
LOG: execute <unnamed>: SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
FROM pg_type as t
LEFT JOIN pg_range as r ON oid = rngtypid
WHERE
t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'text', 'varchar', 'char', 'name', 'bpchar', 'bool', 'bit', 'varbit', 'timestamptz', 'date', 'money', 'bytea', 'point', 'hstore', 'json', 'jsonb', 'cidr', 'inet', 'uuid', 'xml', 'tsvector', 'macaddr', 'citext', 'ltree', 'interval', 'path', 'line', 'polygon', 'circle', 'lseg', 'box', 'time', 'timestamp', 'numeric')
OR t.typtype IN ('r', 'e', 'd')
OR t.typinput::varchar = 'array_in'
OR t.typelem != 0
LOG: statement: SHOW TIME ZONE
LOG: statement: SELECT 1
LOG: execute <unnamed>: SELECT COUNT(*)
FROM pg_class c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view
AND c.relname = 'accounts'
AND n.nspname = ANY (current_schemas(false))
```
2018-11-05 08:47:26 -05:00
|
|
|
execute <<~SQL
|
|
|
|
CREATE PROCEDURE ten() SQL SECURITY INVOKER
|
|
|
|
BEGIN
|
|
|
|
SELECT 10;
|
|
|
|
END
|
|
|
|
SQL
|
2011-10-09 07:38:36 -04:00
|
|
|
|
Use squiggly heredoc to strip odd indentation in the executed SQL
Before:
```
LOG: execute <unnamed>: SELECT t.oid, t.typname
FROM pg_type as t
WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'bool')
LOG: execute <unnamed>: SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
FROM pg_type as t
LEFT JOIN pg_range as r ON oid = rngtypid
WHERE
t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'text', 'varchar', 'char', 'name', 'bpchar', 'bool', 'bit', 'varbit', 'timestamptz', 'date', 'money', 'bytea', 'point', 'hstore', 'json', 'jsonb', 'cidr', 'inet', 'uuid', 'xml', 'tsvector', 'macaddr', 'citext', 'ltree', 'interval', 'path', 'line', 'polygon', 'circle', 'lseg', 'box', 'time', 'timestamp', 'numeric')
OR t.typtype IN ('r', 'e', 'd')
OR t.typinput::varchar = 'array_in'
OR t.typelem != 0
LOG: statement: SHOW TIME ZONE
LOG: statement: SELECT 1
LOG: execute <unnamed>: SELECT COUNT(*)
FROM pg_class c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view
AND c.relname = 'accounts'
AND n.nspname = ANY (current_schemas(false))
```
After:
```
LOG: execute <unnamed>: SELECT t.oid, t.typname
FROM pg_type as t
WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'bool')
LOG: execute <unnamed>: SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
FROM pg_type as t
LEFT JOIN pg_range as r ON oid = rngtypid
WHERE
t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'text', 'varchar', 'char', 'name', 'bpchar', 'bool', 'bit', 'varbit', 'timestamptz', 'date', 'money', 'bytea', 'point', 'hstore', 'json', 'jsonb', 'cidr', 'inet', 'uuid', 'xml', 'tsvector', 'macaddr', 'citext', 'ltree', 'interval', 'path', 'line', 'polygon', 'circle', 'lseg', 'box', 'time', 'timestamp', 'numeric')
OR t.typtype IN ('r', 'e', 'd')
OR t.typinput::varchar = 'array_in'
OR t.typelem != 0
LOG: statement: SHOW TIME ZONE
LOG: statement: SELECT 1
LOG: execute <unnamed>: SELECT COUNT(*)
FROM pg_class c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view
AND c.relname = 'accounts'
AND n.nspname = ANY (current_schemas(false))
```
2018-11-05 08:47:26 -05:00
|
|
|
execute "DROP PROCEDURE IF EXISTS topics"
|
2012-06-27 06:10:36 -04:00
|
|
|
|
Use squiggly heredoc to strip odd indentation in the executed SQL
Before:
```
LOG: execute <unnamed>: SELECT t.oid, t.typname
FROM pg_type as t
WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'bool')
LOG: execute <unnamed>: SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
FROM pg_type as t
LEFT JOIN pg_range as r ON oid = rngtypid
WHERE
t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'text', 'varchar', 'char', 'name', 'bpchar', 'bool', 'bit', 'varbit', 'timestamptz', 'date', 'money', 'bytea', 'point', 'hstore', 'json', 'jsonb', 'cidr', 'inet', 'uuid', 'xml', 'tsvector', 'macaddr', 'citext', 'ltree', 'interval', 'path', 'line', 'polygon', 'circle', 'lseg', 'box', 'time', 'timestamp', 'numeric')
OR t.typtype IN ('r', 'e', 'd')
OR t.typinput::varchar = 'array_in'
OR t.typelem != 0
LOG: statement: SHOW TIME ZONE
LOG: statement: SELECT 1
LOG: execute <unnamed>: SELECT COUNT(*)
FROM pg_class c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view
AND c.relname = 'accounts'
AND n.nspname = ANY (current_schemas(false))
```
After:
```
LOG: execute <unnamed>: SELECT t.oid, t.typname
FROM pg_type as t
WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'bool')
LOG: execute <unnamed>: SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
FROM pg_type as t
LEFT JOIN pg_range as r ON oid = rngtypid
WHERE
t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'text', 'varchar', 'char', 'name', 'bpchar', 'bool', 'bit', 'varbit', 'timestamptz', 'date', 'money', 'bytea', 'point', 'hstore', 'json', 'jsonb', 'cidr', 'inet', 'uuid', 'xml', 'tsvector', 'macaddr', 'citext', 'ltree', 'interval', 'path', 'line', 'polygon', 'circle', 'lseg', 'box', 'time', 'timestamp', 'numeric')
OR t.typtype IN ('r', 'e', 'd')
OR t.typinput::varchar = 'array_in'
OR t.typelem != 0
LOG: statement: SHOW TIME ZONE
LOG: statement: SELECT 1
LOG: execute <unnamed>: SELECT COUNT(*)
FROM pg_class c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view
AND c.relname = 'accounts'
AND n.nspname = ANY (current_schemas(false))
```
2018-11-05 08:47:26 -05:00
|
|
|
execute <<~SQL
|
|
|
|
CREATE PROCEDURE topics(IN num INT) SQL SECURITY INVOKER
|
|
|
|
BEGIN
|
|
|
|
SELECT * FROM topics LIMIT num;
|
|
|
|
END
|
|
|
|
SQL
|
2012-02-25 10:35:58 -05:00
|
|
|
end
|