test_schema.sql 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. DROP DATABASE epgsql_test_db1;
  26. DROP DATABASE epgsql_test_db2;
  27. CREATE DATABASE epgsql_test_db1 WITH ENCODING 'UTF8';
  28. CREATE DATABASE epgsql_test_db2 WITH ENCODING 'UTF8';
  29. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test;
  30. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test_md5;
  31. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test_cleartext;
  32. GRANT ALL ON DATABASE epgsql_test_db2 to epgsql_test;
  33. \c epgsql_test_db1;
  34. CREATE TABLE schema_version (version varchar);
  35. CREATE EXTENSION hstore;
  36. CREATE TABLE test_table1 (id integer primary key, value text);
  37. INSERT INTO test_table1 (id, value) VALUES (1, 'one');
  38. INSERT INTO test_table1 (id, value) VALUES (2, 'two');
  39. CREATE TABLE test_table2 (
  40. c_bool bool,
  41. c_char char,
  42. c_int2 int2,
  43. c_int4 int4,
  44. c_int8 int8,
  45. c_float4 float4,
  46. c_float8 float8,
  47. c_bytea bytea,
  48. c_text text,
  49. c_varchar varchar(64),
  50. c_uuid uuid,
  51. c_date date,
  52. c_time time,
  53. c_timetz timetz,
  54. c_timestamp timestamp,
  55. c_timestamptz timestamptz,
  56. c_interval interval,
  57. c_hstore hstore,
  58. c_cidr cidr,
  59. c_inet inet);
  60. CREATE LANGUAGE plpgsql;
  61. CREATE OR REPLACE FUNCTION insert_test1(_id integer, _value text)
  62. returns integer
  63. as $$
  64. begin
  65. insert into test_table1 (id, value) values (_id, _value);
  66. return _id;
  67. end
  68. $$ language plpgsql;
  69. CREATE OR REPLACE FUNCTION do_nothing()
  70. returns void
  71. as $$
  72. begin
  73. end
  74. $$ language plpgsql;
  75. GRANT ALL ON TABLE test_table1 TO epgsql_test;
  76. GRANT ALL ON TABLE test_table2 TO epgsql_test;
  77. GRANT ALL ON FUNCTION insert_test1(integer, text) TO epgsql_test;
  78. GRANT ALL ON FUNCTION do_nothing() TO epgsql_test;