Hi, Adonis newbie has a problem. So can I create new database table in/via Controller and how it’s done? My app needs to create dynamic tables and I didn’t find any other way to create those than migrations. Thanks!
You could use migrations programmatically. Remember, it’s just JS code.
You can always run a raw query, and just write the
Although, tbh this has a bad code smell. Why do you need to create tables on the fly?
I’m planning to re-write older PHP app with Adonis and that app creates dynamically new containers which can include multiple items. Those containers are dynamically created database tables. There is also one base table which keeps index of these containers.
Do you have suggestions how to accomplish this better way? I could write container contents to JSON object to base table, but contents management feels more complicated then.
I am still not understanding the use case. But you can certainly use JSON for storage. Take a look at
jsonb type in PostgreSQL. It allows you native JSON storage and querying.
Also, you can use automatic serialization of JSON with any database via Lucid.