test_schema.sql 2.3 KB

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