test_schema.sql 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 TABLE test_table1 (id integer primary key, value text);
  33. INSERT INTO test_table1 (id, value) VALUES (1, 'one');
  34. INSERT INTO test_table1 (id, value) VALUES (2, 'two');
  35. CREATE TABLE test_table2 (
  36. c_bool bool,
  37. c_char char,
  38. c_int2 int2,
  39. c_int4 int4,
  40. c_int8 int8,
  41. c_float4 float4,
  42. c_float8 float8,
  43. c_bytea bytea,
  44. c_text text,
  45. c_varchar varchar(64),
  46. c_uuid uuid,
  47. c_date date,
  48. c_time time,
  49. c_timetz timetz,
  50. c_timestamp timestamp,
  51. c_timestamptz timestamptz,
  52. c_interval interval);
  53. CREATE LANGUAGE plpgsql;
  54. CREATE OR REPLACE FUNCTION insert_test1(_id integer, _value text)
  55. returns integer
  56. as $$
  57. begin
  58. insert into test_table1 (id, value) values (_id, _value);
  59. return _id;
  60. end
  61. $$ language plpgsql;
  62. CREATE OR REPLACE FUNCTION do_nothing()
  63. returns void
  64. as $$
  65. begin
  66. end
  67. $$ language plpgsql;
  68. GRANT ALL ON TABLE test_table1 TO epgsql_test;
  69. GRANT ALL ON TABLE test_table2 TO epgsql_test;
  70. GRANT ALL ON FUNCTION insert_test1(integer, text) TO epgsql_test;
  71. GRANT ALL ON FUNCTION do_nothing() TO epgsql_test;