Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting main SQL file into multiple files #1286

Closed
wants to merge 0 commits into from

Conversation

muhammadshoaib
Copy link
Contributor

@muhammadshoaib muhammadshoaib commented Oct 20, 2023

Pull Request: Enhancing Codebase Readability by Converting Main SQL File into Multiple Files

Description:
This pull request is aimed at improving the overall quality of our SQL codebase by converting the main SQL file into multiple smaller files. The primary goal is to enhance code readability, maintainability, and organization for the benefit of the development team.

Changes Made:
In this pull request, several changes have been made to achieve the goal of breaking down the main SQL file into smaller, more manageable pieces:

  • Split the original monolithic SQL file into multiple smaller files, each focusing on specific functionalities or components.
  • Introduced a clear folder structure to organize these SQL files, making it easier for developers to locate the relevant code.
  • Updated any references, imports, or dependencies to adapt to the new file structure.
  • Applied consistent naming conventions for the newly created SQL files.

Why is this change needed?
There are several compelling reasons behind the need for this change:

  1. Improved Readability: The main SQL file has grown significantly over time, becoming difficult to navigate. This change aims to break it down into smaller, more digestible units, improving overall code readability.

  2. Simplified Maintenance: Smaller, well-organized files are easier to maintain. Developers can now work on specific components without affecting the entire codebase, reducing the risk of unintended errors.

  3. Modularity: This change embraces the principle of modularity in software development. Each file now focuses on a specific aspect of our database operations, fostering code reusability and collaboration.

  4. Best Practices: Organizing code into smaller files and directories is a widely-accepted best practice in the software development community. This aligns our project with industry standards.

Checklist:

  • Code has been reviewed.
  • Tests pass successfully.
  • Documentation has been updated (if necessary).

Please take the time to review this pull request thoroughly and provide your feedback. Your input is essential in ensuring the continued improvement of our codebase. Thank you for your collaboration!

@rafsun42
Copy link
Member

@muhammadshoaib Looks good to me. Just one question- If the a sql file change, are we updating the backup to keep them in sync?

Copy link
Member

@MuhammadTahaNaveed MuhammadTahaNaveed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@jrgemignani
Copy link
Contributor

@muhammadshoaib Unfortunately, your PR does not build locally -

============== creating database "contrib_regression" ==============
CREATE DATABASE
ALTER DATABASE
ALTER DATABASE
ALTER DATABASE
ALTER DATABASE
ALTER DATABASE
ALTER DATABASE
============== installing age                         ==============
ERROR:  type agtype does not exist
command failed: "/home/jgemignani/POSTGRESQL/postgresql-15.4/psql-15.4-5432-pgsql/bin/psql" -X -c "CREATE EXTENSION IF NOT EXISTS \"age\"" "contrib_regression"
make: *** [installcheck] Error 2
[jgemignani@cent7nuc7i5bnk incubator-age]$

When I looked at age--1.4.0.sql I noticed the order was not correct, agtype was being defined well after it was being referenced -

  20 --
  21 -- Scalar Functions
  22 --
  23
  24 CREATE FUNCTION ag_catalog.age_id(agtype)
  25     RETURNS agtype
  26     LANGUAGE c
  27     IMMUTABLE
  28 RETURNS NULL ON NULL INPUT
  29 PARALLEL SAFE
  30 AS 'MODULE_PATHNAME';
  31
2384  --
2385 -- agtype type and its support functions
2386 --
2387
2388 -- define agtype as a shell type first
2389 CREATE TYPE agtype;
2390

I believe age--1.4.0.sql needs to be built in a specific order and we need to keep the dependencies in mind.

Additionally, the license block was included multiple times in the finished file. While it is just a comment block, we may want to have just one file, template?, that contains the top of age--x.x.x.sql and then all the other files are appended to that file.

Copy link
Contributor

@jrgemignani jrgemignani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See added notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants