test_schema.sql 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. -- the following lines must be added to pg_hba.conf for all tests to
  7. -- succeed, with $USER replaced by your username, or the user you will
  8. -- run the tests with.
  9. --
  10. -- host epgsql_test_db1 $USER 127.0.0.1/32 trust
  11. -- host epgsql_test_db1 epgsql_test 127.0.0.1/32 trust
  12. -- host epgsql_test_db1 epgsql_test_md5 127.0.0.1/32 md5
  13. -- host epgsql_test_db1 epgsql_test_cleartext 127.0.0.1/32 password
  14. -- hostssl epgsql_test_db1 epgsql_test_cert 127.0.0.1/32 cert
  15. --
  16. -- any 'trust all' must be commented out for the invalid password test
  17. -- to succeed.
  18. --
  19. -- ssl support must be configured, and the sslinfo contrib module
  20. -- loaded for the ssl tests to succeed.
  21. CREATE USER epgsql_test;
  22. CREATE USER epgsql_test_md5 WITH PASSWORD 'epgsql_test_md5';
  23. CREATE USER epgsql_test_cleartext WITH PASSWORD 'epgsql_test_cleartext';
  24. CREATE USER epgsql_test_cert;
  25. CREATE DATABASE epgsql_test_db1 WITH ENCODING 'UTF8';
  26. CREATE DATABASE epgsql_test_db2 WITH ENCODING 'UTF8';
  27. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test;
  28. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test_md5;
  29. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test_cleartext;
  30. GRANT ALL ON DATABASE epgsql_test_db2 to epgsql_test;
  31. \c epgsql_test_db1;
  32. CREATE EXTENSION hstore;
  33. CREATE TABLE test_table1 (id integer primary key, value text);
  34. INSERT INTO test_table1 (id, value) VALUES (1, 'one');
  35. INSERT INTO test_table1 (id, value) VALUES (2, 'two');
  36. CREATE TABLE test_table2 (
  37. c_bool bool,
  38. c_char char,
  39. c_int2 int2,
  40. c_int4 int4,
  41. c_int8 int8,
  42. c_float4 float4,
  43. c_float8 float8,
  44. c_bytea bytea,
  45. c_text text,
  46. c_varchar varchar(64),
  47. c_uuid uuid,
  48. c_date date,
  49. c_time time,
  50. c_timetz timetz,
  51. c_timestamp timestamp,
  52. c_timestamptz timestamptz,
  53. c_interval interval,
  54. c_hstore hstore);
  55. CREATE LANGUAGE plpgsql;
  56. CREATE OR REPLACE FUNCTION insert_test1(_id integer, _value text)
  57. returns integer
  58. as $$
  59. begin
  60. insert into test_table1 (id, value) values (_id, _value);
  61. return _id;
  62. end
  63. $$ language plpgsql;
  64. CREATE OR REPLACE FUNCTION do_nothing()
  65. returns void
  66. as $$
  67. begin
  68. end
  69. $$ language plpgsql;
  70. GRANT ALL ON TABLE test_table1 TO epgsql_test;
  71. GRANT ALL ON TABLE test_table2 TO epgsql_test;
  72. GRANT ALL ON FUNCTION insert_test1(integer, text) TO epgsql_test;
  73. GRANT ALL ON FUNCTION do_nothing() TO epgsql_test;