test_schema.sql 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. c_cidr cidr,
  56. c_inet inet);
  57. CREATE LANGUAGE plpgsql;
  58. CREATE OR REPLACE FUNCTION insert_test1(_id integer, _value text)
  59. returns integer
  60. as $$
  61. begin
  62. insert into test_table1 (id, value) values (_id, _value);
  63. return _id;
  64. end
  65. $$ language plpgsql;
  66. CREATE OR REPLACE FUNCTION do_nothing()
  67. returns void
  68. as $$
  69. begin
  70. end
  71. $$ language plpgsql;
  72. GRANT ALL ON TABLE test_table1 TO epgsql_test;
  73. GRANT ALL ON TABLE test_table2 TO epgsql_test;
  74. GRANT ALL ON FUNCTION insert_test1(integer, text) TO epgsql_test;
  75. GRANT ALL ON FUNCTION do_nothing() TO epgsql_test;