Naming Conventions: Difference between revisions

From nuBuilderForte
Jump to navigation Jump to search
mNo edit summary
[Updated] Naming Conventions
 
Line 1: Line 1:
* All table names are singular and lowercase
* All table names should be '''singular''' and '''lowercase'''


* All field names are lowercase
* All field names should be '''lowercase'''


* Delimit each word in table and field name with an underscore (_). eg., '''grand_total'''
* Use an underscore (_) to separate words in table and field names. 
  e.g., '''grand_total'''


* Add a 3 letter lowercase prefix followed by an underscore (_) to each field which is derived from the table name
* Prefix each field name with a 3-letter lowercase abbreviation of the table name followed by an underscore (_)
  e.g., for the '''person''' table: '''per_name''', '''per_birthdate'''


* '''nuBuilder''' and [https://www.guru99.com/database-normalization.html DB Normalisation rules] requires the use of a Primary Key ('''PK''') for each table
* '''nuBuilder''' and [https://www.guru99.com/database-normalization.html DB Normalisation rules] require a Primary Key ('''PK''') for each table


* Suggested that the PK be the name of the table followed by an underscore ('''_''') and the letters '''id'''. eg., '''person_id'''
* The PK should be the table name followed by an underscore and '''id'''.
  e.g., '''person_id'''


* Suggested that the PK should be a '''varchar(25)''', as it will automatically be populated by '''nuBuilder''' using the function called '''nuID()''' (when filled out as suggested), unless the PK is an ''auto-increment''ing number
* The PK is recommended to be a '''VARCHAR(25)''', auto-generated by '''nuBuilder''' using the '''nuID()''' function 
  (unless using an AUTO_INCREMENT number)


* If a '''varchar(25)''' is used for the PK instead of a number it allows for better use of certain hash cookies such as '''#nu_browse_filter#'''
* Using '''VARCHAR(25)''' for PKs allows better compatibility with hash cookies such as '''#nu_browse_filter#'''


* Also suggested that <u>Unique Indexes not be used</u>, allowing internal validating rules to check for duplicates. This is because of the way the project implements checking for PK types
* It is recommended that <u>Unique Indexes not be used</u>, and instead rely on internal validation rules to handle duplicate checking 
  (due to the way nuBuilder checks for PK uniqueness)


* Foreign Keys (FK) should bear the shortname of the table as a prefix followed by an underscore (_) and then the original parent table's PK it refers to
* Foreign Key ('''FK''') fields should begin with the shortname of the referencing table, followed by an underscore, and then the PK of the referenced table
  e.g., in '''invoice''' table, FK to '''person''' table should be '''inv_person_id'''


== Getting Started ==
== Getting Started ==
* '''Display''' and '''Input''' formatting are stored in the respective system tables ('''zzzzsys_*''') such as '''format, form, browse''' and '''report''' tables.


* Start with own set of tables or have nuBuilder create them on the fly with standard field types that can be altered (do not change the default ID field).
* '''Display''' and '''Input''' formatting are managed through system tables ('''zzzzsys_*'''), such as '''format''', '''form''', '''browse''', and '''report'''


* All nuBuilder application tables must necessarily have '''VARCHAR(25) field type for the primary key ID''' if auto generated in the '''globeadmin''' mode.
* Start with your own tables or allow nuBuilder to generate them with standard field types (do not modify the default ID field)


* Existing tables with other field types like AUTO_INCREMENT INT fields must have their ID fields generated for new records with '''BeforeSave PHP''' code or use '''NULL''' for <u>AUTO_INCREMENT definitions in the DB</u> itself.
* All nuBuilder application tables should use a '''VARCHAR(25)''' type for the PK if auto-generated in '''globeadmin''' mode


* Alternatively, the primary key ID (auto generated or manually made) should follow the VARCHAR(25) convention and keep a ''unique (INT or other) key for what would have been their primary key outside of nuBuilder''.
* For existing tables using AUTO_INCREMENT INT fields, new IDs must be generated via '''BeforeSave PHP''' code 
  or the ID field should be defined as <u>AUTO_INCREMENT NULL</u> in the DB


[[Category: Dashboard]]
* Alternatively, conform to the VARCHAR(25) ID convention and maintain a separate unique INT or other field that previously served as the PK outside of nuBuilder
 
[[Category:Dashboard]]

Latest revision as of 15:31, 6 June 2025

  • All table names should be singular and lowercase
  • All field names should be lowercase
  • Use an underscore (_) to separate words in table and field names.
 e.g., grand_total
  • Prefix each field name with a 3-letter lowercase abbreviation of the table name followed by an underscore (_).
 e.g., for the person table: per_name, per_birthdate
  • The PK should be the table name followed by an underscore and id.
 e.g., person_id
  • The PK is recommended to be a VARCHAR(25), auto-generated by nuBuilder using the nuID() function
 (unless using an AUTO_INCREMENT number)
  • Using VARCHAR(25) for PKs allows better compatibility with hash cookies such as #nu_browse_filter#
  • It is recommended that Unique Indexes not be used, and instead rely on internal validation rules to handle duplicate checking
 (due to the way nuBuilder checks for PK uniqueness)
  • Foreign Key (FK) fields should begin with the shortname of the referencing table, followed by an underscore, and then the PK of the referenced table
 e.g., in invoice table, FK to person table should be inv_person_id

Getting Started

  • Display and Input formatting are managed through system tables (zzzzsys_*), such as format, form, browse, and report
  • Start with your own tables or allow nuBuilder to generate them with standard field types (do not modify the default ID field)
  • All nuBuilder application tables should use a VARCHAR(25) type for the PK if auto-generated in globeadmin mode
  • For existing tables using AUTO_INCREMENT INT fields, new IDs must be generated via BeforeSave PHP code
 or the ID field should be defined as AUTO_INCREMENT NULL in the DB
  • Alternatively, conform to the VARCHAR(25) ID convention and maintain a separate unique INT or other field that previously served as the PK outside of nuBuilder