Skip to content

Commit

Permalink
Add constraints to table row comments
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindberg committed Sep 1, 2023
1 parent a4fd90e commit d45eeeb
Show file tree
Hide file tree
Showing 66 changed files with 476 additions and 233 deletions.
1 change: 0 additions & 1 deletion sql/custom/constraints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ from information_schema.table_constraints tc
join pg_constraint pgc on pgc.conname = cc.constraint_name and pgc.connamespace = nsp.oid and pgc.contype = 'c'
join cols col on col.table_schema = tc.table_schema and col.table_name = tc.table_name and
col.ordinal_position = ANY (pgc.conkey)
where tc.constraint_schema not in ('pg_catalog', 'information_schema')
group by tc.table_schema,
tc.table_name,
tc.constraint_name,
Expand Down
32 changes: 18 additions & 14 deletions typo-scripts/src/scala/scripts/GenHardcodedFiles.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,42 @@ object GenHardcodedFiles extends BleepCodegenScript("GenHardcodedFiles") {
val person = db.Table(
name = db.RelationName(Some("myschema"), "person"),
cols = NonEmptyList(
db.Col(db.ColName("id"), db.Type.Int8, Some("int8"), Nullability.NoNulls, columnDefault = Some("auto-increment"), None, DebugJson.Empty),
db.Col(db.ColName("id"), db.Type.Int8, Some("int8"), Nullability.NoNulls, columnDefault = Some("auto-increment"), None, Nil, DebugJson.Empty),
db.Col(
db.ColName("favourite_football_club_id"),
db.Type.VarChar(Some(50)),
Some("varchar"),
Nullability.NoNulls,
columnDefault = None,
None,
Nil,
DebugJson.Empty
),
db.Col(db.ColName("name"), db.Type.VarChar(Some(100)), Some("varchar"), Nullability.NoNulls, columnDefault = None, None, DebugJson.Empty),
db.Col(db.ColName("nick_name"), db.Type.VarChar(Some(30)), Some("varchar"), Nullability.Nullable, columnDefault = None, None, DebugJson.Empty),
db.Col(db.ColName("blog_url"), db.Type.VarChar(Some(100)), Some("varchar"), Nullability.Nullable, columnDefault = None, None, DebugJson.Empty),
db.Col(db.ColName("email"), db.Type.VarChar(Some(254)), Some("varchar"), Nullability.NoNulls, columnDefault = None, None, DebugJson.Empty),
db.Col(db.ColName("phone"), db.Type.VarChar(Some(8)), Some("varchar"), Nullability.NoNulls, columnDefault = None, None, DebugJson.Empty),
db.Col(db.ColName("likes_pizza"), db.Type.Boolean, Some("bool"), Nullability.NoNulls, columnDefault = None, None, DebugJson.Empty),
db.Col(db.ColName("name"), db.Type.VarChar(Some(100)), Some("varchar"), Nullability.NoNulls, columnDefault = None, None, Nil, DebugJson.Empty),
db.Col(db.ColName("nick_name"), db.Type.VarChar(Some(30)), Some("varchar"), Nullability.Nullable, columnDefault = None, None, Nil, DebugJson.Empty),
db.Col(db.ColName("blog_url"), db.Type.VarChar(Some(100)), Some("varchar"), Nullability.Nullable, columnDefault = None, None, Nil, DebugJson.Empty),
db.Col(db.ColName("email"), db.Type.VarChar(Some(254)), Some("varchar"), Nullability.NoNulls, columnDefault = None, None, Nil, DebugJson.Empty),
db.Col(db.ColName("phone"), db.Type.VarChar(Some(8)), Some("varchar"), Nullability.NoNulls, columnDefault = None, None, Nil, DebugJson.Empty),
db.Col(db.ColName("likes_pizza"), db.Type.Boolean, Some("bool"), Nullability.NoNulls, columnDefault = None, None, Nil, DebugJson.Empty),
db.Col(
db.ColName("marital_status_id"),
db.Type.VarChar(Some(50)),
Some("varchar"),
Nullability.NoNulls,
columnDefault = Some("some-value"),
None,
Nil,
DebugJson.Empty
),
db.Col(db.ColName("work_email"), db.Type.VarChar(Some(254)), Some("varchar"), Nullability.Nullable, columnDefault = None, None, DebugJson.Empty),
db.Col(db.ColName("work_email"), db.Type.VarChar(Some(254)), Some("varchar"), Nullability.Nullable, columnDefault = None, None, Nil, DebugJson.Empty),
db.Col(
db.ColName("sector"),
db.Type.EnumRef(db.RelationName(Some("myschema"), "sector")),
Some("myschema.sector"),
Nullability.NoNulls,
columnDefault = Some("PUBLIC"),
None,
Nil,
DebugJson.Empty
),
db.Col(
Expand All @@ -59,6 +62,7 @@ object GenHardcodedFiles extends BleepCodegenScript("GenHardcodedFiles") {
Nullability.NoNulls,
columnDefault = Some("one"),
None,
Nil,
DebugJson.Empty
)
),
Expand All @@ -82,8 +86,8 @@ object GenHardcodedFiles extends BleepCodegenScript("GenHardcodedFiles") {
val football_club = db.Table(
name = db.RelationName(Some("myschema"), "football_club"),
cols = NonEmptyList(
db.Col(db.ColName("id"), db.Type.Int8, Some("int8"), Nullability.NoNulls, columnDefault = None, None, DebugJson.Empty),
db.Col(db.ColName("name"), db.Type.VarChar(Some(100)), Some("varchar"), Nullability.NoNulls, columnDefault = None, None, DebugJson.Empty)
db.Col(db.ColName("id"), db.Type.Int8, Some("int8"), Nullability.NoNulls, columnDefault = None, None, Nil, DebugJson.Empty),
db.Col(db.ColName("name"), db.Type.VarChar(Some(100)), Some("varchar"), Nullability.NoNulls, columnDefault = None, None, Nil, DebugJson.Empty)
),
Some(db.PrimaryKey(NonEmptyList(db.ColName("id")), db.RelationName(Some("myschema"), "football_club_pkey"))),
Nil,
Expand All @@ -92,7 +96,7 @@ object GenHardcodedFiles extends BleepCodegenScript("GenHardcodedFiles") {
val marital_status = db.Table(
name = db.RelationName(Some("myschema"), "marital_status"),
cols = NonEmptyList(
db.Col(db.ColName("id"), db.Type.Int8, Some("int8"), Nullability.NoNulls, columnDefault = None, None, DebugJson.Empty)
db.Col(db.ColName("id"), db.Type.Int8, Some("int8"), Nullability.NoNulls, columnDefault = None, None, Nil, DebugJson.Empty)
),
Some(db.PrimaryKey(NonEmptyList(db.ColName("id")), db.RelationName(Some("myschema"), "marital_status_pkey"))),
Nil,
Expand All @@ -102,9 +106,9 @@ object GenHardcodedFiles extends BleepCodegenScript("GenHardcodedFiles") {
val cpk_person = db.Table(
name = db.RelationName(Some("compositepk"), "person"), // name clash to ensure we handle it
cols = NonEmptyList(
db.Col(db.ColName("one"), db.Type.Int8, Some("int8"), Nullability.NoNulls, columnDefault = Some("auto-increment"), None, DebugJson.Empty),
db.Col(db.ColName("two"), db.Type.Text, Some("text"), Nullability.Nullable, columnDefault = Some("auto-increment"), None, DebugJson.Empty),
db.Col(db.ColName("name"), db.Type.Text, Some("text"), Nullability.Nullable, columnDefault = None, None, DebugJson.Empty)
db.Col(db.ColName("one"), db.Type.Int8, Some("int8"), Nullability.NoNulls, columnDefault = Some("auto-increment"), None, Nil, DebugJson.Empty),
db.Col(db.ColName("two"), db.Type.Text, Some("text"), Nullability.Nullable, columnDefault = Some("auto-increment"), None, Nil, DebugJson.Empty),
db.Col(db.ColName("name"), db.Type.Text, Some("text"), Nullability.Nullable, columnDefault = None, None, Nil, DebugJson.Empty)
),
Some(db.PrimaryKey(NonEmptyList(db.ColName("one"), db.ColName("two")), db.RelationName(Some("compositepk"), "person_pkey"))),
Nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,25 @@ case class EmployeeRow(
loginid: /* max 256 chars */ String,
/** Work title such as Buyer or Sales Representative. */
jobtitle: /* max 50 chars */ String,
/** Date of birth. */
/** Date of birth.
Constraint CK_Employee_BirthDate affecting columns "birthdate": (((birthdate >= '1930-01-01'::date) AND (birthdate <= (now() - '18 years'::interval)))) */
birthdate: TypoLocalDate,
/** M = Married, S = Single */
/** M = Married, S = Single
Constraint CK_Employee_MaritalStatus affecting columns "maritalstatus": ((upper((maritalstatus)::text) = ANY (ARRAY['M'::text, 'S'::text]))) */
maritalstatus: /* bpchar, max 1 chars */ String,
/** M = Male, F = Female */
/** M = Male, F = Female
Constraint CK_Employee_Gender affecting columns "gender": ((upper((gender)::text) = ANY (ARRAY['M'::text, 'F'::text]))) */
gender: /* bpchar, max 1 chars */ String,
/** Employee hired on this date. */
/** Employee hired on this date.
Constraint CK_Employee_HireDate affecting columns "hiredate": (((hiredate >= '1996-07-01'::date) AND (hiredate <= (now() + '1 day'::interval)))) */
hiredate: TypoLocalDate,
/** Job classification. 0 = Hourly, not exempt from collective bargaining. 1 = Salaried, exempt from collective bargaining. */
salariedflag: Flag,
/** Number of available vacation hours. */
/** Number of available vacation hours.
Constraint CK_Employee_VacationHours affecting columns "vacationhours": (((vacationhours >= '-40'::integer) AND (vacationhours <= 240))) */
vacationhours: TypoShort,
/** Number of available sick leave hours. */
/** Number of available sick leave hours.
Constraint CK_Employee_SickLeaveHours affecting columns "sickleavehours": (((sickleavehours >= 0) AND (sickleavehours <= 120))) */
sickleavehours: TypoShort,
/** 0 = Inactive, 1 = Active */
currentflag: Flag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ case class EmployeedepartmenthistoryRow(
/** Identifies which 8-hour shift the employee works. Foreign key to Shift.Shift.ID.
Points to [[shift.ShiftRow.shiftid]] */
shiftid: ShiftId,
/** Date the employee started work in the department. */
/** Date the employee started work in the department.
Constraint CK_EmployeeDepartmentHistory_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */
startdate: TypoLocalDate,
/** Date the employee left the department. NULL = Current department. */
/** Date the employee left the department. NULL = Current department.
Constraint CK_EmployeeDepartmentHistory_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */
enddate: Option[TypoLocalDate],
modifieddate: TypoLocalDateTime
){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ case class EmployeepayhistoryRow(
businessentityid: BusinessentityId,
/** Date the change in pay is effective */
ratechangedate: TypoLocalDateTime,
/** Salary hourly rate. */
/** Salary hourly rate.
Constraint CK_EmployeePayHistory_Rate affecting columns "rate": (((rate >= 6.50) AND (rate <= 200.00))) */
rate: BigDecimal,
/** 1 = Salary received monthly, 2 = Salary received biweekly */
/** 1 = Salary received monthly, 2 = Salary received biweekly
Constraint CK_EmployeePayHistory_PayFrequency affecting columns "payfrequency": ((payfrequency = ANY (ARRAY[1, 2]))) */
payfrequency: TypoShort,
modifieddate: TypoLocalDateTime
){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ case class PersonRow(
/** Primary key for Person records.
Points to [[businessentity.BusinessentityRow.businessentityid]] */
businessentityid: BusinessentityId,
/** Primary type of person: SC = Store Contact, IN = Individual (retail) customer, SP = Sales person, EM = Employee (non-sales), VC = Vendor contact, GC = General contact */
/** Primary type of person: SC = Store Contact, IN = Individual (retail) customer, SP = Sales person, EM = Employee (non-sales), VC = Vendor contact, GC = General contact
Constraint CK_Person_PersonType affecting columns "persontype": (((persontype IS NULL) OR (upper((persontype)::text) = ANY (ARRAY['SC'::text, 'VC'::text, 'IN'::text, 'EM'::text, 'SP'::text, 'GC'::text])))) */
persontype: /* bpchar, max 2 chars */ String,
/** 0 = The data in FirstName and LastName are stored in western style (first name, last name) order. 1 = Eastern style (last name, first name) order. */
namestyle: NameStyle,
Expand All @@ -44,7 +45,8 @@ case class PersonRow(
lastname: Name,
/** Surname suffix. For example, Sr. or Jr. */
suffix: Option[/* max 10 chars */ String],
/** 0 = Contact does not wish to receive e-mail promotions, 1 = Contact does wish to receive e-mail promotions from AdventureWorks, 2 = Contact does wish to receive e-mail promotions from AdventureWorks and selected partners. */
/** 0 = Contact does not wish to receive e-mail promotions, 1 = Contact does wish to receive e-mail promotions from AdventureWorks, 2 = Contact does wish to receive e-mail promotions from AdventureWorks and selected partners.
Constraint CK_Person_EmailPromotion affecting columns "emailpromotion": (((emailpromotion >= 0) AND (emailpromotion <= 2))) */
emailpromotion: Int,
/** Additional contact information about the person stored in xml format. */
additionalcontactinfo: Option[TypoXml],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,29 @@ case class BillofmaterialsRow(
/** Primary key for BillOfMaterials records. */
billofmaterialsid: BillofmaterialsId,
/** Parent product identification number. Foreign key to Product.ProductID.
Points to [[product.ProductRow.productid]] */
Points to [[product.ProductRow.productid]]
Constraint CK_BillOfMaterials_BOMLevel affecting columns "bomlevel", "productassemblyid", "perassemblyqty": ((((productassemblyid IS NULL) AND (bomlevel = 0) AND (perassemblyqty = 1.00)) OR ((productassemblyid IS NOT NULL) AND (bomlevel >= 1))))
Constraint CK_BillOfMaterials_ProductAssemblyID affecting columns "productassemblyid", "componentid": ((productassemblyid <> componentid)) */
productassemblyid: Option[ProductId],
/** Component identification number. Foreign key to Product.ProductID.
Points to [[product.ProductRow.productid]] */
Points to [[product.ProductRow.productid]]
Constraint CK_BillOfMaterials_ProductAssemblyID affecting columns "productassemblyid", "componentid": ((productassemblyid <> componentid)) */
componentid: ProductId,
/** Date the component started being used in the assembly item. */
/** Date the component started being used in the assembly item.
Constraint CK_BillOfMaterials_EndDate affecting columns "enddate", "startdate": (((enddate > startdate) OR (enddate IS NULL))) */
startdate: TypoLocalDateTime,
/** Date the component stopped being used in the assembly item. */
/** Date the component stopped being used in the assembly item.
Constraint CK_BillOfMaterials_EndDate affecting columns "enddate", "startdate": (((enddate > startdate) OR (enddate IS NULL))) */
enddate: Option[TypoLocalDateTime],
/** Standard code identifying the unit of measure for the quantity.
Points to [[unitmeasure.UnitmeasureRow.unitmeasurecode]] */
unitmeasurecode: UnitmeasureId,
/** Indicates the depth the component is from its parent (AssemblyID). */
/** Indicates the depth the component is from its parent (AssemblyID).
Constraint CK_BillOfMaterials_BOMLevel affecting columns "bomlevel", "productassemblyid", "perassemblyqty": ((((productassemblyid IS NULL) AND (bomlevel = 0) AND (perassemblyqty = 1.00)) OR ((productassemblyid IS NOT NULL) AND (bomlevel >= 1)))) */
bomlevel: TypoShort,
/** Quantity of the component needed to create the assembly. */
/** Quantity of the component needed to create the assembly.
Constraint CK_BillOfMaterials_BOMLevel affecting columns "bomlevel", "productassemblyid", "perassemblyqty": ((((productassemblyid IS NULL) AND (bomlevel = 0) AND (perassemblyqty = 1.00)) OR ((productassemblyid IS NOT NULL) AND (bomlevel >= 1))))
Constraint CK_BillOfMaterials_PerAssemblyQty affecting columns "perassemblyqty": ((perassemblyqty >= 1.00)) */
perassemblyqty: BigDecimal,
modifieddate: TypoLocalDateTime
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ case class DocumentRow(
revision: /* bpchar, max 5 chars */ String,
/** Engineering change approval number. */
changenumber: Int,
/** 1 = Pending approval, 2 = Approved, 3 = Obsolete */
/** 1 = Pending approval, 2 = Approved, 3 = Obsolete
Constraint CK_Document_Status affecting columns "status": (((status >= 1) AND (status <= 3))) */
status: TypoShort,
/** Document abstract. */
documentsummary: Option[String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ case class LocationRow(
locationid: LocationId,
/** Location description. */
name: Name,
/** Standard hourly cost of the manufacturing location. */
/** Standard hourly cost of the manufacturing location.
Constraint CK_Location_CostRate affecting columns "costrate": ((costrate >= 0.00)) */
costrate: BigDecimal,
/** Work capacity (in hours) of the manufacturing location. */
/** Work capacity (in hours) of the manufacturing location.
Constraint CK_Location_Availability affecting columns "availability": ((availability >= 0.00)) */
availability: BigDecimal,
modifieddate: TypoLocalDateTime
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ case class ProductRow(
finishedgoodsflag: Flag,
/** Product color. */
color: Option[/* max 15 chars */ String],
/** Minimum inventory quantity. */
/** Minimum inventory quantity.
Constraint CK_Product_SafetyStockLevel affecting columns "safetystocklevel": ((safetystocklevel > 0)) */
safetystocklevel: TypoShort,
/** Inventory level that triggers a purchase order or work order. */
/** Inventory level that triggers a purchase order or work order.
Constraint CK_Product_ReorderPoint affecting columns "reorderpoint": ((reorderpoint > 0)) */
reorderpoint: TypoShort,
/** Standard cost of the product. */
/** Standard cost of the product.
Constraint CK_Product_StandardCost affecting columns "standardcost": ((standardcost >= 0.00)) */
standardcost: BigDecimal,
/** Selling price. */
/** Selling price.
Constraint CK_Product_ListPrice affecting columns "listprice": ((listprice >= 0.00)) */
listprice: BigDecimal,
/** Product size. */
size: Option[/* max 5 chars */ String],
Expand All @@ -56,25 +60,32 @@ case class ProductRow(
/** Unit of measure for Weight column.
Points to [[unitmeasure.UnitmeasureRow.unitmeasurecode]] */
weightunitmeasurecode: Option[UnitmeasureId],
/** Product weight. */
/** Product weight.
Constraint CK_Product_Weight affecting columns "weight": ((weight > 0.00)) */
weight: Option[BigDecimal],
/** Number of days required to manufacture the product. */
/** Number of days required to manufacture the product.
Constraint CK_Product_DaysToManufacture affecting columns "daystomanufacture": ((daystomanufacture >= 0)) */
daystomanufacture: Int,
/** R = Road, M = Mountain, T = Touring, S = Standard */
/** R = Road, M = Mountain, T = Touring, S = Standard
Constraint CK_Product_ProductLine affecting columns "productline": (((upper((productline)::text) = ANY (ARRAY['S'::text, 'T'::text, 'M'::text, 'R'::text])) OR (productline IS NULL))) */
productline: Option[/* bpchar, max 2 chars */ String],
/** H = High, M = Medium, L = Low */
/** H = High, M = Medium, L = Low
Constraint CK_Product_Class affecting columns "class": (((upper((class)::text) = ANY (ARRAY['L'::text, 'M'::text, 'H'::text])) OR (class IS NULL))) */
`class`: Option[/* bpchar, max 2 chars */ String],
/** W = Womens, M = Mens, U = Universal */
/** W = Womens, M = Mens, U = Universal
Constraint CK_Product_Style affecting columns "style": (((upper((style)::text) = ANY (ARRAY['W'::text, 'M'::text, 'U'::text])) OR (style IS NULL))) */
style: Option[/* bpchar, max 2 chars */ String],
/** Product is a member of this product subcategory. Foreign key to ProductSubCategory.ProductSubCategoryID.
Points to [[productsubcategory.ProductsubcategoryRow.productsubcategoryid]] */
productsubcategoryid: Option[ProductsubcategoryId],
/** Product is a member of this product model. Foreign key to ProductModel.ProductModelID.
Points to [[productmodel.ProductmodelRow.productmodelid]] */
productmodelid: Option[ProductmodelId],
/** Date the product was available for sale. */
/** Date the product was available for sale.
Constraint CK_Product_SellEndDate affecting columns "sellenddate", "sellstartdate": (((sellenddate >= sellstartdate) OR (sellenddate IS NULL))) */
sellstartdate: TypoLocalDateTime,
/** Date the product was no longer available for sale. */
/** Date the product was no longer available for sale.
Constraint CK_Product_SellEndDate affecting columns "sellenddate", "sellstartdate": (((sellenddate >= sellstartdate) OR (sellenddate IS NULL))) */
sellenddate: Option[TypoLocalDateTime],
/** Date the product was discontinued. */
discontinueddate: Option[TypoLocalDateTime],
Expand Down
Loading

0 comments on commit d45eeeb

Please sign in to comment.