-- This file and its contents are licensed under the Apache License 2.0.
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.
\c :TEST_DBNAME :ROLE_SUPERUSER
CREATE DATABASE trusted_test;
GRANT CREATE ON DATABASE trusted_test TO :ROLE_1;
\c trusted_test :ROLE_READ_ONLY
\set ON_ERROR_STOP 0
CREATE EXTENSION timescaledb;
ERROR:  permission denied to create extension "timescaledb"
\set ON_ERROR_STOP 1
\c trusted_test :ROLE_1
-- user shouldn't have superuser privilege
SELECT rolsuper FROM pg_roles WHERE rolname=user;
 rolsuper 
----------
 f

SET client_min_messages TO ERROR;
CREATE EXTENSION timescaledb;
RESET client_min_messages;
CREATE TABLE t(time timestamptz);
SELECT create_hypertable('t','time');
 create_hypertable 
-------------------
 (1,public,t,t)

INSERT INTO t VALUES ('2000-01-01'), ('2001-01-01');
SELECT * FROM t ORDER BY 1;
             time             
------------------------------
 Sat Jan 01 00:00:00 2000 PST
 Mon Jan 01 00:00:00 2001 PST

SELECT * FROM timescaledb_information.hypertables;
 hypertable_schema | hypertable_name |    owner    | num_dimensions | num_chunks | compression_enabled | tablespaces | primary_dimension |  primary_dimension_type  
-------------------+-----------------+-------------+----------------+------------+---------------------+-------------+-------------------+--------------------------
 public            | t               | test_role_1 |              1 |          2 | f                   |             | time              | timestamp with time zone

SELECT * FROM test.relation WHERE schema = '_timescaledb_internal' AND name LIKE '\_hyper%';
        schema         |       name       | type  |    owner    
-----------------------+------------------+-------+-------------
 _timescaledb_internal | _hyper_1_1_chunk | table | test_role_1
 _timescaledb_internal | _hyper_1_2_chunk | table | test_role_1

DROP EXTENSION timescaledb CASCADE;
NOTICE:  drop cascades to 2 other objects
\c :TEST_DBNAME :ROLE_SUPERUSER
DROP DATABASE trusted_test WITH (FORCE);
