jonseg / crud-admin-generator

An open source tool to generate a complete backend from a MySql database.
http://crud-admin-generator.com/
MIT License
1.43k stars 441 forks source link

Adapt crud-admin-generator to work using PostgreSQL #122

Open bepetersn opened 5 years ago

bepetersn commented 5 years ago

I don't know if someone will find this useful, but it seems possible because I needed it. This breaks support for MySQL and I'm not making an attempt to fix that, so please don't consider this an actual pull request as I don't want to break your library. Rather, I hope this helps someone. If you wanted to try to incorporate it, I think it could be manageable. Thanks for doing the work you did on this.

In order to query the columns from each table it was convenient for me to construct a VIEW to make the query a little shorter. Here's how I defined that view:

CREATE VIEW table_column_constraints as (SELECT c.table_schema, c.table_name, c.column_name , c.data_type , c.is_nullable , tc.constraint_type
, c.column_default FROM information_schema.columns AS c LEFT JOIN information_schema.constraint_column_usage AS ccu USING (column_name, table_name) LEFT JOIN information_schema.table_constraints tc ON tc.constraint_name=ccu.constraint_name WHERE c.table_schema='public');

NOTE: I haven't taken the time to get bulk downloads working. Not sure what is wrong. Everything else appears to be working as a baseline. There are also some ephemeral errors on update which I haven't fixed because they only flash on-screen before disappearing and the update succeeding.

bepetersn commented 5 years ago

For others, calling it postgres, pgsql as well