Hello,
I have an old Semi ERP application with back end powered by PostgreSQL. I am planning to try to build the whole app in Frappe Framework from scratch.
There are 300+ tables and around 1k stored procedures and 750+ views.
To build this application we had employed 12 developers for 24 months.
It would prove to be a nightmare to build DocTypes for each table.
Are there any tools which will reverse engineer an existing database and generate DocTypes?
TIA
Yogi Yang
Not sure if anyone has done this by reverse engineering from total another schema type, But i guess it will not take much time to create 300 doctypes, since this would be a one-time process, even if you write some script like the below attached u would have to define fields mapping so instead you can create itself manually (By dividing among 12 )
The script would be prone to error and manually you can configure correctly since those would be handled through f/w itself
1 Like
Hello @khushal_t ,
Your suggestion is valid from your stand point because you are just looking at 300+ tables.
But if you look from my point of view it would be an impossible task as I will have to update various triggers, heavily edit all SPs and what not.
It would truly be a nightmare.
While I am at it I also want to ask whether we can force Frappe Framework to use pure table name instead of prefixing all table names with tab
.
TIA
Yogi Yang
tab prefix
There is no option to remove the ‘tab’ prefix. This is hardcoded in 'database.py
’ and a few other places in the framework. You’d have to alter that code yourself, and maintain your edits.
Here are a few examples of code:
DocType auto-builder
There are no tools for reverse engineering PostgreSQL tables + stored procedures + views, and transforming into DocTypes.
That sounds extremely cool, though.
2 Likes
peterg
September 8, 2022, 4:14am
5
Can you say more about this?
As others have said, translating table schemas to frappe doctypes should be doable, with a few caveats. If you’re hoping to automatically convert sql triggers to frappe controller methods, however, that’s probably going to be very challenging.
1 Like
Hello,
I just want to convert Tables to DocTypes and nothing else.
The rest will work automatically at Database server level. Provided table names are maintained as they are.
I am not looking at converting Triggers, SPs, etc.
TIA
Yogi Yang
peterg
September 8, 2022, 9:06am
7
You might look at the Virtual Doctype feature that was introduced in v13 but much improved in v14. It allows you to define arbitrary backend storage.
3 Likes
This is an interesting suggestion.
I am interested in trying to use this feature. Is there any working and well commented sample of Virtual DocType that I can refer to, to learn about this sleek feature?
Regards,
avc
September 16, 2022, 6:34am
9
Take a look here …
https://frappeframework.com/docs/v14/user/en/basics/doctypes/virtual-doctype
And this PR uses virtual doctype approach
frappe:develop
← ankush:rq_redo
opened 09:18PM - 10 Sep 22 UTC
BREAKING CHANGE: This PR removes "Background Jobs" page.
Debugging RQ behavi… or seems to be damn near impossible with no proper UI for it. I've almost always had to SSH to the server and see wtf is going on.
The "Background Jobs" page exists but is completely broken and technically not even correctly implemented. At present, it's incapable of viewing anything other than queued jobs which makes it kinda pointless because they go away in seconds often.
I don't want to spend any time on building UIs for dev debugging tools, so virtual doctypes to the rescue. #lowcode or something.
Before:
1. Worker page
<img width="1440" alt="Screenshot 2022-09-11 at 1 29 27 AM" src="https://user-images.githubusercontent.com/9079960/189502053-64d202df-b38b-4386-90fe-f67e50dffac3.png">
2. Jobs page - doesn't work lol.
After:
1. Worker page
<img width="1440" alt="Screenshot 2022-09-11 at 5 10 56 PM" src="https://user-images.githubusercontent.com/9079960/189525563-a7c73ebb-ac00-40d9-aaf5-265478e5c243.png">
<img width="1440" alt="Screenshot 2022-09-11 at 5 09 44 PM" src="https://user-images.githubusercontent.com/9079960/189525567-4f7b76a5-2320-44eb-abb5-7db39e5ae759.png">
3. Job Pages
List view - filtering on queue and status is supported
<img width="1440" alt="Screenshot 2022-09-11 at 4 57 20 PM" src="https://user-images.githubusercontent.com/9079960/189525604-50d6f73c-863f-452e-b344-61f6d2565593.png">
Form page with meta info
<img width="1440" alt="Screenshot 2022-09-11 at 5 05 10 PM" src="https://user-images.githubusercontent.com/9079960/189525628-e333206e-61bb-40a5-8566-f6b6c8709229.png">
Error logging, only errors that escaped FW's error logging.
<img width="1440" alt="Screenshot 2022-09-11 at 5 05 17 PM" src="https://user-images.githubusercontent.com/9079960/189525613-8ce52408-8b5a-4027-b70b-af5d64634d1e.png">
Forcefully kill a stuck job
<img width="1440" alt="Screenshot 2022-09-11 at 7 28 22 PM" src="https://user-images.githubusercontent.com/9079960/189531898-459f17bb-0f56-407a-8c49-1eeba365dc67.png">
They also show A LOT more information compared to the previous custom page.
TODO:
- [x] RQ worker doctype with stats
- [x] RQ job doctype with details
- [x] RQ jobs filtering - using status and queue
- [x] reduce failed job TTL to 7 days (from 1 year!)
- [x] Delete failed jobs, single + bulk
- [x] Scheduler status
- [x] Deprecate and remove old page once all functionality is migrated.
- [x] Forcefully stop a stuck job. (_HERE BE DRAGONS_)
- [x] Tests for almost everything
Unrelated changes:
- Removed code to re-enable scheduler which was never running, ref https://github.com/frappe/frappe/issues/16023
- serialize function object to their repr in `frappe.as_json` https://github.com/frappe/frappe/pull/18086/commits/0eabf783df6a2fbca25e231e7324dd4e0c608b6c
docs: https://frappeframework.com/docs/v14/user/en/profiling
Hope this helps.
Hello,
Thank you for the link. I have already studied this. But I want to understand, what happens if the SQL query returns fields which are not declared in the DocType?
TIA
Yogi Yang
avc
September 16, 2022, 7:51am
11
Well, you have to write your own controller (on .py file) that connects to your db, launch the quere, read and transform the data, adapting to the doctype requirements.
Sample:
you have a virtual doctype with First Name, Last Name and Age.
you have a external database with First Name, Last Name, Age and Address
When you receive the data you will consider only the first 3 fields, and must adapt this to the virtual doctype structure (meta fields too: creation date, ownler, assign …). It is not easy, but Virtual Doctypes is a amazing feature.
Hope this helps.
3 Likes