On-the-fly schemas/resources?
Hi! I have a rather particular use case IDK how to code in Ash. A client is asking for per-user databases, with an arbitrary number of tables and properties. Something like Notion, Supabase, or Airtable. This user generated data can change at any time, but for obvious reasons I can't recompile the whole app every time something does change. Ideally, every user should have their own little SQLite DB for their personal data, although I could be persuaded to store everything in Postgres, maybe with JSONB for simplicity.
Can this be done with Ash? I know I can code the base system in it, but I can't for the life of me figure out how to handle ever-changing resources. Is this possible, or feasible?
10 Replies
Not really, no 🙂
I know this does not relate to Ash, but sounds like you need something similar to this: https://github.com/basecamp/activerecord-tenanted
GitHub
GitHub - basecamp/activerecord-tenanted: Enable a Rails application...
Enable a Rails application to have separate databases for each tenant. - basecamp/activerecord-tenanted
It's a complex problem I've been thinking about for a while, so everything you can say about it helps, thanks
I don't have much knowledge from the Ash side of things, and it might depend on exactly what the client requires, but there 2 concerns here:
1: per-tenant or per-user databases which feels like something that Ash could handle even if doesn't currently.
2: does the client really require different database tables and columns, or is this the user-facing requirement? If the latter, then it feels like something that can be handled with appropriate data modeling. You may not be able to have different Ash Resources or Attributes per schema but that doesn't mean it can't be presented to the user in that way.
Yeah the thing is we as developers have literally no idea what shape a user defined DB might have. It can be pretty much anything.
So, there goes all the facilities that come from modelling the data using resources instead of old boring schema.
I can, of course, model my own app using Ash, but any user can add new DBs, tables, whatever, at any time, to their own account. Change the shape of the data, perform any number of destructive or creative actions, etc. Because we're basically a platform for building data rich applications. Think Notion meets no-code UI, probably.
I'm starting to realize I will probably have to manually roll some sort of minimal Ash clone myself. At least something that lets me translate JSON API <-> SQL statements automatically. I think there are some libraries for that already. Still researching though
Just because they are called "databases" and "tables" in the UI for the user, does it mean that the implementation has to be actual databases and database tables?
Not necessarily, but probably yes. We're exploring possibilities, like JSONB columns and such, but the easiest implementation seems to be a SQLite as a service thing some company provides
Have you looked at any NoSQL DBs? They often have tooling to specify and evolve/version schemas for documents over time.
I have a lot of experience with MongoDB, yes. But the final form of the data is not the real problem.. the real problem here is exposing, in an unattended fashion, an interface flexible enough that can safely describe data of an arbitrary shape, without any human intervention whatsoever. The user facing interface needs to be user friendly, the DB itself needs to be at least somewhat advanced, and the users need to be able to handle everything by themselves...
Microsoft Access? Just kidding. I see, it's the interface that you're after, probably Ash isn't going to help with that.