sixarm_sql_schema_examples
SixArm » SQL » Schema examples
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (3.6%) to scientific vocabulary
Keywords
Repository
SixArm » SQL » Schema examples
Statistics
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
SixArm → SQL → Schema examples
Contents:
Schema examples
Most popular:
Access control:
Geography:
- geolocation
- country
- country_subdivision
- region
- locality
- street_address
- neighborhood
- postal_code
- postal_address
Business:
- brand
- currency
- currencyconversionservice
- currency_pair
- exchangeratespecification
- market_area
- market_sector
- money_range
- money_transfer
- money_value
- offer
- payment_service
- product
- trade_action
Accounts:
Misc:
Schema conventions
General standardizations
Use industry standard schemas such as the Schema.org project.
- For example, a postal address has a field for "locality", not "city".
Use International System of Units (SI), such as the metric system.
- For example, the field name "height" is intended to use a unit of a meter, not a unit of a foot as in the Imperial system and United States customary system.
Dates and times
Use date formats and time formats that are consistent with ISO standard formats.
- For example, the timestamp display format is Year-Month-Day and Hour:Minute:Second and "Z" i.e. Zulu time zone, such as "YYYY-MM-DDTHH:MM:SSZ"
Any date or time field must be in UTC, unless the filed is deliberately representing local time, in which case the field name must use the suffix "_local" because this helps with disambiguation.
- For example, the "person" table has the field name "birthdatelocal" because we care about the person's local date birthday, not Zulu date birthday.
If you are using PostgreSQL, then you may want to change the "timestamp" data type to the PostgreSQL extension "timestamptz" data type.
- For example, the "event" table has the entry "startwhen timestamp"; if you are using PostgreSQL, you probably want to change this field to "startwhen timestamptz" for Zulu time, or "startwhenlocal timestamp" for local time.
Our SQL conventions
Use a table name that is singular, not plural.
- For example, the examples have a "person" table, not "persons" nor "people".
Use lowercase SQL, rather than uppercase SQL.
- For example, the examples use "create table", not "CREATE TABLE".
Our field name conventions
If a field can be a relation and/or freeform text, then use two fields, one with field name suffix "id" and one with field name suffix "ie" meaning "I.e., in other words".
- For example, a field name "statusid" is intended to be a relation to the "status" table, and a field name "statusie" is intended to be freeform text that user can enter.
If fields are intended to be a range, then prefer "start" and "stop", not "begin" and "end", nor "from" and "to".
- For example, the table "event" has a start time and stop time, not a begin time and end time.
Use a field name with a long meaningful name, not an abbreviation nor initialism.
- For example, use "latitude", not "lat".
Languages
We prefer to work with multiple languages. For example, we often use English, Spanish, Chinese, and many other languages.
- For example, a person's name in English is "Amy" and in French is "Aimée".
We use a naming convention of "{field}as{language}".
- For example, the table "person" has a field name "nameasen" meaning "the name as English", and a field name "nameasfr" meaning the name as French.
For the example files here, we list English, French, and Spanish. This is so you can see how multiple languages can work.
You can add more languages if you want.
Some developers prefer different ways of handling languages, naming, internationalization, and localization. You can customize the files as you like for your goals.
Types
Use typical data type default sizes.
- For example, we use the data type "varchar" as a default, when we don't know a text field will be somewhat short.
Use numeric data type with a large range, rather than float data type, because we prefer consistency over fluidity.
- For example, we prefer numeric(20,12) as a general-purpose number type; you can change these as you like.
Use the word "numeric" instead of "decimal" because its clearer, such as for integrations.
- For example, we prefer numeric(x,y) over decimal(x,y).
Optimizations
Fast speed is more important than space, so we prefer some denormalization.
- For example, some tables duplicate the field name "postal_code", because many of our apps use it to speed up local search.
Handling corner cases well is more important than space.
- For example, the concepts of a "region" and "country_subdivision" are nearly identical, but not quite, so we store both.
Providing usable represenations is more important than space.
- For example, the table "person" and table "organization" both have a field name "vcard" that stores the VCard VCF text, and a field name "hcard" that stores the VCard as a HCard HTML microformat.
Bonus fields for growth
In practice we often add some bonus fields to each table; these fields help us with the growth of the app, and also the administration of the app.
Secure random primary keys
Example:
sql
-- We prefer using secure random 128-bit numbers as primary keys.
-- These numbers are storable in a typical PostgreSQL UUID field.
id uuid not null primary key,
Optimistic locking
Example:
sql
-- An incrementing number that an application can
-- use for optimistic locking for read/write speed
lock_version int,
Change tracking
sql
-- Track who touches the record and when,
-- because this information helps in practice
-- for diagnosing the application as it runs.
created_at timestamp, created_by uuid references user,
updated_at timestamp, updated_by uuid references user,
proofed_at timestamp, proofed_by uuid references user,
retired_at timestamp, retired_by uuid references user,
Single table inheritance
Example:
sql
-- The field name "type" is a reserved word in some frameworks,
-- which uses the field for single-table inheritance.
type varchar,
Position order
Example:
sql
-- The field name "position" is a reserved word in some frameworks,
-- which uses the field for ordering by position index number.
position integer,
Parent pointer
Example:
sql
-- For a record that has a direct parent record
parent_id uuid references self,
Status
Example:
sql
-- Status table suitable for the app
status_id uuid references status,
status_ie varchar,
For more information
Example:
sql
-- Ways to see more about the record, such as a URL to more information, and a note of text.
uri varchar,
note longtext,
Liquibase annotation
Liquibase is an open source tool for managing database schema changes.
See https://en.wikipedia.org/wiki/Liquibase
Our projects use database schema changes within source code, and within large projects, so we have schema examples here to help new projects.
Why we use Liquibase SQL vs. XML vs. YAML
Liquibase files can be written in SQL, or XML, or YAML. We prefer SQL because more database administrators know it.
If you prefer XML or YAML and would like to translate our examples, then we welcome the help and also welcome pull requests.
Tracking
- Package: sixarmsqlschema_examples
- Version: 8.3.1
- Created: 1996-01-01
- Updated: 2019-05-16
- License: BSD, MIT, GPL
- Contact: Joel Parker Henderson (http://joelparkerhenderson.com)
Owner
- Name: SixArm
- Login: SixArm
- Kind: organization
- Email: sixarm@sixarm.com
- Location: San Francisco
- Website: http://sixarm.com
- Twitter: sixarm
- Repositories: 580
- Profile: https://github.com/SixArm
SixArm Software
Citation (CITATION.cff)
cff-version: 1.2.0
title: SixArm → SQL → Schema examples
message: >-
If you use this work and you want to cite it,
then you can use the metadata from this file.
type: software
authors:
- given-names: Joel Parker
family-names: Henderson
email: joel@joelparkerhenderson.com
affiliation: joelparkerhenderson.com
orcid: 'https://orcid.org/0009-0000-4681-282X'
identifiers:
- type: url
value: 'https://github.com/SixArm/sixarm_sql_schema_examples/'
description: SixArm → SQL → Schema examples
repository-code: 'https://github.com/SixArm/sixarm_sql_schema_examples/'
abstract: >-
SixArm → SQL → Schema examples
license: See license file
GitHub Events
Total
- Push event: 1
Last Year
- Push event: 1
Committers
Last synced: 11 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Joel Parker Henderson | j****l@j****m | 97 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 10 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0