test_schema.sql 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. -- ssl support must be configured, and the sslinfo contrib module
  7. -- loaded for the ssl tests to succeed.
  8. -- NOTE: you will need the postgis extensions to run these tests!
  9. -- On Ubuntu, you can install them with a command like this:
  10. -- apt-get install postgresql-9.3-postgis-2.1
  11. CREATE USER epgsql_test;
  12. CREATE USER epgsql_test_md5 WITH PASSWORD 'epgsql_test_md5';
  13. CREATE USER epgsql_test_cleartext WITH PASSWORD 'epgsql_test_cleartext';
  14. CREATE USER epgsql_test_cert;
  15. DROP DATABASE epgsql_test_db1;
  16. DROP DATABASE epgsql_test_db2;
  17. CREATE DATABASE epgsql_test_db1 WITH ENCODING 'UTF8';
  18. CREATE DATABASE epgsql_test_db2 WITH ENCODING 'UTF8';
  19. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test;
  20. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test_md5;
  21. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test_cleartext;
  22. GRANT ALL ON DATABASE epgsql_test_db2 to epgsql_test;
  23. \c epgsql_test_db1;
  24. DROP TABLE schema_version;
  25. CREATE TABLE schema_version (version varchar);
  26. -- This requires Postgres to be compiled with SSL:
  27. -- http://www.postgresql.org/docs/9.4/static/sslinfo.html
  28. CREATE EXTENSION sslinfo;
  29. CREATE EXTENSION hstore;
  30. CREATE EXTENSION postgis;
  31. CREATE TABLE test_table1 (id integer primary key, value text);
  32. INSERT INTO test_table1 (id, value) VALUES (1, 'one');
  33. INSERT INTO test_table1 (id, value) VALUES (2, 'two');
  34. CREATE TABLE test_table2 (
  35. c_bool bool,
  36. c_char char,
  37. c_int2 int2,
  38. c_int4 int4,
  39. c_int8 int8,
  40. c_float4 float4,
  41. c_float8 float8,
  42. c_bytea bytea,
  43. c_text text,
  44. c_varchar varchar(64),
  45. c_uuid uuid,
  46. c_date date,
  47. c_time time,
  48. c_timetz timetz,
  49. c_timestamp timestamp,
  50. c_timestamptz timestamptz,
  51. c_interval interval,
  52. c_hstore hstore,
  53. c_point point,
  54. c_geometry geometry,
  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 schema_version TO epgsql_test;
  73. GRANT ALL ON TABLE test_table1 TO epgsql_test;
  74. GRANT ALL ON TABLE test_table2 TO epgsql_test;
  75. GRANT ALL ON FUNCTION insert_test1(integer, text) TO epgsql_test;
  76. GRANT ALL ON FUNCTION do_nothing() TO epgsql_test;