test_schema.sql 1.9 KB

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