test_schema.sql 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. -- script to create test schema for epgsql unit tests --
  2. --
  3. -- this script should be run as the same user the tests will be run as,
  4. -- so that the test for connecting as the 'current user' succeeds
  5. --
  6. -- ssl support must be configured, and the sslinfo contrib module
  7. -- loaded for the ssl tests to succeed.
  8. CREATE USER epgsql_test;
  9. CREATE USER epgsql_test_md5 WITH PASSWORD 'epgsql_test_md5';
  10. CREATE USER epgsql_test_cleartext WITH PASSWORD 'epgsql_test_cleartext';
  11. CREATE USER epgsql_test_cert;
  12. CREATE USER epgsql_test_replication WITH REPLICATION PASSWORD 'epgsql_test_replication';
  13. SET password_encryption TO 'scram-sha-256';
  14. CREATE USER epgsql_test_scram WITH PASSWORD 'epgsql_test_scram';
  15. SET password_encryption TO 'md5';
  16. CREATE DATABASE epgsql_test_db1 WITH ENCODING 'UTF8';
  17. CREATE DATABASE epgsql_test_db2 WITH ENCODING 'UTF8';
  18. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test;
  19. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test_md5;
  20. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test_scram;
  21. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test_cleartext;
  22. GRANT ALL ON DATABASE epgsql_test_db2 to epgsql_test;
  23. \c epgsql_test_db1;
  24. CREATE TABLE schema_version (version varchar);
  25. -- This requires Postgres to be compiled with SSL:
  26. -- http://www.postgresql.org/docs/9.4/static/sslinfo.html
  27. CREATE EXTENSION sslinfo;
  28. CREATE EXTENSION hstore;
  29. CREATE EXTENSION postgis;
  30. CREATE TABLE test_table1 (id integer primary key, value text);
  31. INSERT INTO test_table1 (id, value) VALUES (1, 'one');
  32. INSERT INTO test_table1 (id, value) VALUES (2, 'two');
  33. CREATE TABLE test_table2 (
  34. c_bool bool,
  35. c_char char,
  36. c_int2 int2,
  37. c_int4 int4,
  38. c_int8 int8,
  39. c_float4 float4,
  40. c_float8 float8,
  41. c_bytea bytea,
  42. c_text text,
  43. c_varchar varchar(64),
  44. c_uuid uuid,
  45. c_date date,
  46. c_time time,
  47. c_timetz timetz,
  48. c_timestamp timestamp,
  49. c_timestamptz timestamptz,
  50. c_interval interval,
  51. c_hstore hstore,
  52. c_point point,
  53. c_geometry geometry,
  54. c_cidr cidr,
  55. c_inet inet,
  56. c_macaddr macaddr,
  57. c_int4range int4range,
  58. c_int8range int8range,
  59. c_json json,
  60. c_jsonb jsonb,
  61. c_tsrange tsrange,
  62. c_tstzrange tstzrange,
  63. c_daterange daterange
  64. );
  65. -- CREATE LANGUAGE plpgsql;
  66. CREATE OR REPLACE FUNCTION insert_test1(_id integer, _value text)
  67. returns integer
  68. as $$
  69. begin
  70. insert into test_table1 (id, value) values (_id, _value);
  71. return _id;
  72. end
  73. $$ language plpgsql;
  74. CREATE OR REPLACE FUNCTION do_nothing()
  75. returns void
  76. as $$
  77. begin
  78. end
  79. $$ language plpgsql;
  80. GRANT ALL ON TABLE test_table1 TO epgsql_test;
  81. GRANT ALL ON TABLE test_table2 TO epgsql_test;
  82. GRANT ALL ON FUNCTION insert_test1(integer, text) TO epgsql_test;
  83. GRANT ALL ON FUNCTION do_nothing() TO epgsql_test;