statement ok
CREATE DATABASE d;
GRANT CREATE ON DATABASE d TO testuser;

# By default, testuser should have ALL privileges on a types it creates and
# Public should have usage.
user testuser

statement ok
USE d;

statement ok
CREATE TYPE testuser_t AS ENUM();

query TTTTTB colnames,rowsort
SHOW GRANTS ON TYPE testuser_t;
----
database_name  schema_name  type_name   grantee   privilege_type  is_grantable
d              public       testuser_t  admin     ALL             true
d              public       testuser_t  public    USAGE           false
d              public       testuser_t  root      ALL             true
d              public       testuser_t  testuser  ALL             true

statement ok
ALTER DEFAULT PRIVILEGES REVOKE ALL ON TYPES FROM testuser;
ALTER DEFAULT PRIVILEGES REVOKE USAGE ON TYPES FROM public;
ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE ALL ON TYPES FROM testuser;
ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE USAGE ON TYPES FROM public;

statement ok
CREATE TYPE testuser_t2 AS ENUM();

query TTTTTB colnames,rowsort
SHOW GRANTS ON TYPE testuser_t2
----
database_name  schema_name  type_name    grantee   privilege_type  is_grantable
d              public       testuser_t2  admin     ALL             true
d              public       testuser_t2  root      ALL             true
d              public       testuser_t2  testuser  ALL             true

user root

statement ok
USE test;

statement ok
CREATE USER testuser2

statement ok
ALTER DEFAULT PRIVILEGES GRANT ALL ON TYPES TO testuser, testuser2

statement ok
CREATE TYPE t AS ENUM()

query TTTTTB colnames,rowsort
SHOW GRANTS ON TYPE t
----
database_name  schema_name  type_name  grantee    privilege_type  is_grantable
test           public       t          admin      ALL             true
test           public       t          public     USAGE           false
test           public       t          root       ALL             true
test           public       t          testuser   ALL             false
test           public       t          testuser2  ALL             false

statement ok
ALTER DEFAULT PRIVILEGES REVOKE USAGE ON TYPES FROM testuser, testuser2

statement ok
CREATE TYPE t2 AS ENUM()

query TTTTTB colnames,rowsort
SHOW GRANTS ON TYPE t2
----
database_name  schema_name  type_name  grantee  privilege_type  is_grantable
test           public       t2         admin    ALL             true
test           public       t2         public   USAGE           false
test           public       t2         root     ALL             true

statement ok
ALTER DEFAULT PRIVILEGES REVOKE ALL ON TYPES FROM testuser, testuser2

statement ok
CREATE TYPE t3 AS ENUM()

query TTTTTB colnames,rowsort
SHOW GRANTS ON TYPE t3
----
database_name  schema_name  type_name  grantee  privilege_type  is_grantable
test           public       t3         admin    ALL             true
test           public       t3         public   USAGE           false
test           public       t3         root     ALL             true

statement ok
GRANT CREATE ON DATABASE d TO testuser

user testuser
statement ok
USE d

statement ok
ALTER DEFAULT PRIVILEGES FOR ROLE testuser REVOKE ALL ON TYPES FROM testuser, testuser2

statement ok
CREATE TYPE t4 AS ENUM()

query TTTTTB colnames,rowsort
SHOW GRANTS ON TYPE t4
----
database_name  schema_name  type_name  grantee   privilege_type  is_grantable
d              public       t4         admin     ALL             true
d              public       t4         root      ALL             true
d              public       t4         testuser  ALL             true

user root
statement ok
USE d

statement ok
ALTER DEFAULT PRIVILEGES FOR ROLE testuser REVOKE ALL ON TYPES FROM testuser, testuser2

user testuser
statement ok
USE d

statement ok
CREATE TYPE t5 AS ENUM()

query TTTTTB colnames,rowsort
SHOW GRANTS ON TYPE t5
----
database_name  schema_name  type_name  grantee   privilege_type  is_grantable
d              public       t5         admin     ALL             true
d              public       t5         root      ALL             true
d              public       t5         testuser  ALL             true
