test_schema.sql 2.2 KB

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