test_schema.sql 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. -- NOTE: you will need the postgis extensions to run these tests!
  22. -- On Ubuntu, you can install them with a command like this:
  23. -- apt-get install postgresql-9.3-postgis-2.1
  24. CREATE USER epgsql_test;
  25. CREATE USER epgsql_test_md5 WITH PASSWORD 'epgsql_test_md5';
  26. CREATE USER epgsql_test_cleartext WITH PASSWORD 'epgsql_test_cleartext';
  27. CREATE USER epgsql_test_cert;
  28. DROP DATABASE epgsql_test_db1;
  29. DROP DATABASE epgsql_test_db2;
  30. CREATE DATABASE epgsql_test_db1 WITH ENCODING 'UTF8';
  31. CREATE DATABASE epgsql_test_db2 WITH ENCODING 'UTF8';
  32. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test;
  33. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test_md5;
  34. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test_cleartext;
  35. GRANT ALL ON DATABASE epgsql_test_db2 to epgsql_test;
  36. \c epgsql_test_db1;
  37. CREATE TABLE schema_version (version varchar);
  38. -- This requires Postgres to be compiled with SSL:
  39. -- http://www.postgresql.org/docs/9.4/static/sslinfo.html
  40. CREATE EXTENSION sslinfo;
  41. CREATE EXTENSION hstore;
  42. CREATE EXTENSION postgis;
  43. CREATE TABLE test_table1 (id integer primary key, value text);
  44. INSERT INTO test_table1 (id, value) VALUES (1, 'one');
  45. INSERT INTO test_table1 (id, value) VALUES (2, 'two');
  46. CREATE TABLE test_table2 (
  47. c_bool bool,
  48. c_char char,
  49. c_int2 int2,
  50. c_int4 int4,
  51. c_int8 int8,
  52. c_float4 float4,
  53. c_float8 float8,
  54. c_bytea bytea,
  55. c_text text,
  56. c_varchar varchar(64),
  57. c_uuid uuid,
  58. c_date date,
  59. c_time time,
  60. c_timetz timetz,
  61. c_timestamp timestamp,
  62. c_timestamptz timestamptz,
  63. c_interval interval,
  64. c_hstore hstore,
  65. c_point point,
  66. c_geometry geometry,
  67. c_cidr cidr,
  68. c_inet inet);
  69. CREATE LANGUAGE plpgsql;
  70. CREATE OR REPLACE FUNCTION insert_test1(_id integer, _value text)
  71. returns integer
  72. as $$
  73. begin
  74. insert into test_table1 (id, value) values (_id, _value);
  75. return _id;
  76. end
  77. $$ language plpgsql;
  78. CREATE OR REPLACE FUNCTION do_nothing()
  79. returns void
  80. as $$
  81. begin
  82. end
  83. $$ language plpgsql;
  84. GRANT ALL ON TABLE schema_version TO epgsql_test;
  85. GRANT ALL ON TABLE test_table1 TO epgsql_test;
  86. GRANT ALL ON TABLE test_table2 TO epgsql_test;
  87. GRANT ALL ON FUNCTION insert_test1(integer, text) TO epgsql_test;
  88. GRANT ALL ON FUNCTION do_nothing() TO epgsql_test;