— postgresql, express, react, node, sequelize, coding project — 1 min read
I wanted to try setting up my own app from start to finish, because while I'm good at maintaining and developing features, I've not had the chance to set something up for myself.
Note: I won't rewrite the referenced tutorials above, just pick out some parts that I use frequently and put them here.
sequelize-cli
, which then automatically creates a migration file for the model.1npx sequelize-cli model:generate --name Ingredient --attributes 'name:string, variant:string, price:jsonb, nutritional_value:jsonb, serving:jsonb, created_at:date, updated_at:date'
1npx sequelize-cli migration:generate --name add-ingredient-list-to-recipe
Had to define many-to-many association, and it was quite confusing.
1include: [2 {3 model: Ingredient,4 through: 'RecipeIngredient'5 }, // load the recipe ingredients6 ]
I'm using PostgreSQL as my RDBMS of choice, because I want to be very familiar with it. I was exposed to it through work, and I want to take this opportunity to explore more.
1select table_name, pg_relation_size(quote_ident(table_name))2from information_schema.tables3where table_schema = 'public'4order by 2
1select table_name, pg_size_pretty( pg_relation_size(quote_ident(table_name)) )2 from information_schema.tables3 where table_schema = 'public'4 order by pg_relation_size(quote_ident(table_name)) desc
public
. Ref1SELECT2 schema_name,3 relname,4 pg_size_pretty(table_size) AS size,5 table_size67FROM (8 SELECT9 pg_catalog.pg_namespace.nspname AS schema_name,10 relname,11 pg_relation_size(pg_catalog.pg_class.oid) AS table_size1213 FROM pg_catalog.pg_class14 JOIN pg_catalog.pg_namespace ON relnamespace = pg_catalog.pg_namespace.oid15 ) t16WHERE schema_name NOT LIKE 'pg_%'17ORDER BY table_size DESC;