test_schema.sql 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. DROP DATABASE epgsql_test_db1;
  14. DROP DATABASE epgsql_test_db2;
  15. CREATE DATABASE epgsql_test_db1 WITH ENCODING 'UTF8';
  16. CREATE DATABASE epgsql_test_db2 WITH ENCODING 'UTF8';
  17. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test;
  18. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test_md5;
  19. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test_cleartext;
  20. GRANT ALL ON DATABASE epgsql_test_db2 to epgsql_test;
  21. \c epgsql_test_db1;
  22. DROP TABLE schema_version;
  23. CREATE TABLE schema_version (version varchar);
  24. -- This requires Postgres to be compiled with SSL:
  25. -- http://www.postgresql.org/docs/9.4/static/sslinfo.html
  26. CREATE EXTENSION sslinfo;
  27. CREATE EXTENSION hstore;
  28. CREATE EXTENSION postgis;
  29. CREATE TABLE test_table1 (id integer primary key, value text);
  30. INSERT INTO test_table1 (id, value) VALUES (1, 'one');
  31. INSERT INTO test_table1 (id, value) VALUES (2, 'two');
  32. CREATE TABLE test_table2 (
  33. c_bool bool,
  34. c_char char,
  35. c_int2 int2,
  36. c_int4 int4,
  37. c_int8 int8,
  38. c_float4 float4,
  39. c_float8 float8,
  40. c_bytea bytea,
  41. c_text text,
  42. c_varchar varchar(64),
  43. c_uuid uuid,
  44. c_date date,
  45. c_time time,
  46. c_timetz timetz,
  47. c_timestamp timestamp,
  48. c_timestamptz timestamptz,
  49. c_interval interval,
  50. c_hstore hstore,
  51. c_point point,
  52. c_geometry geometry,
  53. c_cidr cidr,
  54. c_inet inet,
  55. c_int4range int4range,
  56. c_json json,
  57. c_jsonb jsonb);
  58. CREATE LANGUAGE plpgsql;
  59. CREATE OR REPLACE FUNCTION insert_test1(_id integer, _value text)
  60. returns integer
  61. as $$
  62. begin
  63. insert into test_table1 (id, value) values (_id, _value);
  64. return _id;
  65. end
  66. $$ language plpgsql;
  67. CREATE OR REPLACE FUNCTION do_nothing()
  68. returns void
  69. as $$
  70. begin
  71. end
  72. $$ language plpgsql;
  73. GRANT ALL ON TABLE schema_version TO epgsql_test;
  74. GRANT ALL ON TABLE test_table1 TO epgsql_test;
  75. GRANT ALL ON TABLE test_table2 TO epgsql_test;
  76. GRANT ALL ON FUNCTION insert_test1(integer, text) TO epgsql_test;
  77. GRANT ALL ON FUNCTION do_nothing() TO epgsql_test;