saayam-for-all / database

Both saaaym-web and saayam-mobile apps would use a common DB. This repo contains all DB specific code and content.
0 stars 1 forks source link

Create a new proposed schema for Saayam database with tables and corresponding fields #6

Open chimabc opened 1 month ago

chimabc commented 1 month ago

Proposed Schema for Saayam-For-All Database

Branch "https://github.com/saayam-for-all/database/tree/swatic_proposed_schema" contains following 2 folders with corresponding SQL script file. We only need to run one SQL script to generate schema and tables within that schema. Note: We can rename the schema and tables/fields as we review. Just need to modify one file.

image For example, If you are using PostgreSQL, go to 'Using PostgreSQL and pgAdmin4 Tool' folder, follow "Using PostgreSQL and pgAdmin4 Tools" steps and execute the given SQL script file to generate schema and corresponding tables. You would see something like this in the pgAdmin4 tool after successful execution of the script.

PostgreSQL-pgAdmin4-Saayam-Query-Execution

============== Using PostgreSQL and pgAdmin4 Tools: To execute the provided PostgreSQL script using pgAdmin 4, follow these steps:

Open pgAdmin 4:

Launch pgAdmin 4 from your application menu or desktop shortcut. Connect to your PostgreSQL server by selecting it from the left-hand tree view and entering your password if prompted.

Open the Query Tool: In the left-hand tree view, navigate to the database where you want to execute the script. Right-click on the database and select Query Tool from the context menu. This will open a new Query Tool tab.

Load the Script: In the Query Tool, click the Open File icon (or press Ctrl+O). Browse to the location where your PostgreSQL script file is saved, select it, and click Open. The script will be loaded into the Query Tool editor.

Execute the Script: Once the script is loaded into the Query Tool editor, review it to ensure it is correct and complete. Click the Execute/Refresh icon (or press F5) to run the script. pgAdmin will execute the script and display the results and any messages in the Output pane at the bottom of the Query Tool.

Review the Output: Check the Output pane for any errors or confirmation messages indicating the script was executed successfully.

Steps to Create ER Diagram in pgAdmin 4

Open pgAdmin 4: Launch pgAdmin 4 from your application menu or desktop shortcut. Connect to your PostgreSQL server by selecting it from the left-hand tree view and entering your password if prompted. Navigate to the Database:

In the left-hand tree view, navigate to the database that contains your schema.

Access the ERD Tool: Right-click on the database and select Generate ERD (Beta) from the context menu. If this option is not available, you may need to install the ERD tool as a plugin or extension.

Generate the ER Diagram: A new tab will open in pgAdmin 4 with the ERD tool. You may need to select the schema or tables you want to include in the ER diagram.

Customize the ER Diagram: Use the tools provided in the ERD tab to arrange, label, and customize the appearance of your ER diagram. You can move tables around to better visualize relationships and add notes or comments if needed.

Save the ER Diagram: Once you are satisfied with the ER diagram, you can save it for future reference. There should be an option to export the diagram as an image or a PDF for documentation purposes.

ER Diagram from Current Proposed Schema Note: I tried my best to make this ER diagram readable. Unfortunately, PostgreSQL ERD tool is quite challenging to manage ERD. Hence, I used MySQL Workbench which is much easier to create readable ERD. Step-by-step instructions on how to use MySQL to create a schema and ERD using that schema are listed below.

PostgreSQL-Proposed-DB-ERD-Diagram pgerd

===============

Steps to Execute a MySQL Query File in MySQL Workbench

Open MySQL Workbench: Launch MySQL Workbench from your application menu or desktop shortcut.

Connect to Your MySQL Server: In the MySQL Workbench Home screen, click on the MySQL connection you want to use. Enter your username and password if prompted.

Open the Query File: In the menu bar, go to File > Open SQL Script.... Navigate to the location where your .sql file is saved, select it, and click Open.

Review the SQL Script: The contents of the .sql file will be displayed in a new query tab in MySQL Workbench. Review the script to ensure it's correct and ready for execution.

Execute the Script: To execute the script, click the lightning bolt icon (Execute) in the toolbar, or press Ctrl + Shift + Enter. MySQL Workbench will run the SQL script and execute all the commands in the file.

Monitor the Execution: Monitor the output pane at the bottom of the Workbench window for any messages or errors during execution. If there are errors, they will be displayed here, and you may need to correct them in the script and re-execute.

You would see something like this in the MySQL Workbench tool after successful execution of the script. MySQL-Workbench-Saayam-Query-Execution

Steps to Create an ER Diagram in MySQL Workbench

Open MySQL Workbench: Launch MySQL Workbench from your application menu or desktop shortcut.

Connect to Your MySQL Server: In the MySQL Workbench Home screen, click on the MySQL connection you want to use. Enter your username and password if prompted.

Load the Schema: Ensure that your schema (database) is loaded. You should have already executed your SQL script that creates the schema and tables.

Create an ER Diagram: In the menu bar, go to Database > Reverse Engineer....

Reverse Engineer Database: In the Reverse Engineer Wizard, select the database/schema for which you want to create the ER diagram.

Follow the steps in the wizard: Select the database connection. Select the schema you want to reverse engineer. The wizard will retrieve the schema objects, and you can proceed by clicking Next until the process is complete.

Arrange the Diagram: Once the reverse engineering process is complete, the ER diagram will be displayed in a new tab. You can manually arrange the tables and relationships by dragging them to your preferred layout. Use the toolbar options to adjust the diagram view, such as zooming in/out or auto-layout.

Save the ER Diagram: To save the ER diagram, go to File > Save Model As... and choose the location and file name. You can also export the diagram as an image or PDF by going to File > Export and choosing the desired format.

MySQL-Workbench-Saayam-Query-Execution

MySQL-Saayam-Proposed-DB-ERD