test_schema.sql 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. CREATE USER epgsql_test;
  16. CREATE USER epgsql_test_md5 WITH PASSWORD 'epgsql_test_md5';
  17. CREATE USER epgsql_test_cleartext WITH PASSWORD 'epgsql_test_cleartext';
  18. CREATE DATABASE epgsql_test_db1;
  19. CREATE DATABASE epgsql_test_db2;
  20. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test;
  21. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test_md5;
  22. GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test_cleartext;
  23. GRANT ALL ON DATABASE epgsql_test_db2 to epgsql_test;
  24. \c epgsql_test_db1;
  25. CREATE TABLE test_table1 (id integer primary key, value text);
  26. INSERT INTO test_table1 (id, value) VALUES (1, 'one');
  27. INSERT INTO test_table1 (id, value) VALUES (2, 'two');
  28. CREATE TABLE test_table2 (
  29. c_bool bool,
  30. c_char char,
  31. c_int2 int2,
  32. c_int4 int4,
  33. c_int8 int8,
  34. c_float4 float4,
  35. c_float8 float8,
  36. c_bytea bytea,
  37. c_text text,
  38. c_varchar varchar(64),
  39. c_date date,
  40. c_time time,
  41. c_timetz timetz,
  42. c_timestamp timestamp,
  43. c_timestamptz timestamptz,
  44. c_interval interval);
  45. CREATE LANGUAGE plpgsql;
  46. CREATE OR REPLACE FUNCTION insert_test1(_id integer, _value text)
  47. returns integer
  48. as $$
  49. begin
  50. insert into test_table1 (id, value) values (_id, _value);
  51. return _id;
  52. end
  53. $$ language plpgsql;
  54. CREATE OR REPLACE FUNCTION do_nothing()
  55. returns void
  56. as $$
  57. begin
  58. end
  59. $$ language plpgsql;
  60. GRANT ALL ON TABLE test_table1 TO epgsql_test;
  61. GRANT ALL ON TABLE test_table2 TO epgsql_test;
  62. GRANT ALL ON FUNCTION insert_test1(integer, text) TO epgsql_test;
  63. GRANT ALL ON FUNCTION do_nothing() TO epgsql_test;