Multiple Views, One Schema: Simple RBAC with Duality Views
In this article, we’ll explore how JSON Relational Duality Views can be used to decompose a schema into subdomains – allowing role-based isolation of data to relevant services.
If you’d like to follow along with this article, I recommend using Oracle Database Free.
Imagine a website that takes product orders for various customers. You’d need products, orders, and customers tables something like this:
To facilitate proper isolation and security, you’d also want different APIs for managing products, customer profiles, and customer orders.
Now, you could divide up these tables into separate schemas, create responsible services, and generally adhere to microservices patterns. This is potentially a lot of workfor your average developer.
But what if there was a simpler way to keep service isolation, while retaining a single database schema?
Enter JSON Relational Duality Views
Duality views expose JSON documents across one or more related tables. For example, a CustomerOrder service that writes customer orders only needs write access to the orders table, but read access to customers and products.
We can easily model this with a JSON Relational Duality View, using the GraphQL syntax:
Inserting a record via this duality view allows referencing customer and product IDs. The database then creates the corresponding order row automatically:
We can easily imagine other views on this schema – For example, a customer view that allows customers read-only access to their orders, or an admin view that allows write access to products in the store.
Each view can have its own role, separating responsibilities out to different services:
createusercustomer_orders_service identified by Welcome12345;grantselect, inserton orders_dv to orders_service;createuserorders_service identified by Welcome12345;grantselecton customer_orders to customer_orders_service;createuserproduct_admin_user identified by Welcome12345;grantselect, insert, update, deleteon product_admin to product_admin_user;
Using these roles, we can implement separate services for managing customer orders, general orders, and product administration.
I’ll leave this as an exercise to the reader, but it could be done as custom CRUD web services, or quickly bootstrapped using Oracle REST Data Services.
Leave a Reply