resource "postgresql_grant" "pd_etldb_owner_db_all" {
  database    = postgresql_database.pd_etldb.name
  role        = postgresql_role.pd_etldb_owner.name
  object_type = "database"
  privileges  = ["CONNECT", "CREATE", "TEMPORARY"]
}

resource "postgresql_grant" "pd_etldb_owner_schema_all" {
  database    = postgresql_database.pd_etldb.name
  role        = postgresql_role.pd_etldb_owner.name
  schema      = postgresql_schema.pd_etldb_public.name
  object_type = "schema"
  privileges  = ["USAGE", "CREATE"]
}

resource "postgresql_grant" "pd_etldb_owner_table_all" {
  database    = postgresql_database.pd_etldb.name
  role        = postgresql_role.pd_etldb_owner.name
  schema      = postgresql_schema.pd_etldb_public.name
  object_type = "table"
  privileges  = ["SELECT", "INSERT", "UPDATE", "DELETE", "TRUNCATE", "REFERENCES", "TRIGGER"]
}

resource "postgresql_grant" "pd_etldb_owner_sequence_all" {
  database    = postgresql_database.pd_etldb.name
  role        = postgresql_role.pd_etldb_owner.name
  schema      = postgresql_schema.pd_etldb_public.name
  object_type = "sequence"
  privileges  = ["SELECT", "UPDATE", "USAGE"]
}

resource "postgresql_grant" "pd_etldb_user_db_connect" {
  database    = postgresql_database.pd_etldb.name
  role        = postgresql_role.pd_etldb_user.name
  object_type = "database"
  privileges  = ["CONNECT"]
}

resource "postgresql_grant" "pd_etldb_user_schema_ro" {
  database    = postgresql_database.pd_etldb.name
  role        = postgresql_role.pd_etldb_user.name
  schema      = postgresql_schema.pd_etldb_public.name
  object_type = "schema"
  privileges  = ["USAGE"]
}

resource "postgresql_grant" "pd_etldb_user_table_rw" {
  database    = postgresql_database.pd_etldb.name
  role        = postgresql_role.pd_etldb_user.name
  schema      = postgresql_schema.pd_etldb_public.name
  object_type = "table"
  privileges  = ["SELECT", "INSERT", "UPDATE", "DELETE", "TRUNCATE"]
}

resource "postgresql_grant" "pd_etldb_user_sequence_rw" {
  database    = postgresql_database.pd_etldb.name
  role        = postgresql_role.pd_etldb_user.name
  schema      = postgresql_schema.pd_etldb_public.name
  object_type = "sequence"
  privileges  = ["SELECT", "UPDATE", "USAGE"]
}

resource "postgresql_grant" "pd_etldb_reader_db_connect" {
  database    = postgresql_database.pd_etldb.name
  role        = postgresql_role.pd_etldb_reader.name
  object_type = "database"
  privileges  = ["CONNECT"]
}

resource "postgresql_grant" "pd_etldb_reader_schema_ro" {
  database    = postgresql_database.pd_etldb.name
  role        = postgresql_role.pd_etldb_reader.name
  schema      = postgresql_schema.pd_etldb_public.name
  object_type = "schema"
  privileges  = ["USAGE"]
}

resource "postgresql_grant" "pd_etldb_reader_table_ro" {
  database    = postgresql_database.pd_etldb.name
  role        = postgresql_role.pd_etldb_reader.name
  schema      = postgresql_schema.pd_etldb_public.name
  object_type = "table"
  privileges  = ["SELECT"]
}

resource "postgresql_grant" "pd_etldb_reader_sequence_ro" {
  database    = postgresql_database.pd_etldb.name
  role        = postgresql_role.pd_etldb_reader.name
  schema      = postgresql_schema.pd_etldb_public.name
  object_type = "sequence"
  privileges  = ["SELECT", "USAGE"]
}
