From 10b209e7431d508074c2c88434e7b55227e690ea Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Sat, 2 Mar 2024 12:22:30 -0500 Subject: [PATCH] wip format --- Makefile | 4 ++-- sql/format-sql.sh | 6 ------ sql/format.sh | 7 +++++++ sql/tables.sql | 16 +++++++++------- 4 files changed, 18 insertions(+), 15 deletions(-) delete mode 100755 sql/format-sql.sh create mode 100755 sql/format.sh diff --git a/Makefile b/Makefile index 9edc19a..c029d44 100644 --- a/Makefile +++ b/Makefile @@ -35,8 +35,8 @@ run: pnpm dev .PHONY: format -format: ## pnpm format - pnpm format +format: ## format SQL with pg_format + ./sql/format.sh .PHONY: lint lint: ## pnpm lint && pnpm check diff --git a/sql/format-sql.sh b/sql/format-sql.sh deleted file mode 100755 index 32b0965..0000000 --- a/sql/format-sql.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -cd "$(dirname "$0")" - -pg_format -s 2 tables.sql -o tables.sql -# pg_format -s 2 import.sql -o import.sql diff --git a/sql/format.sh b/sql/format.sh new file mode 100755 index 0000000..8cc5c17 --- /dev/null +++ b/sql/format.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +cd "$(dirname "$0")" + +# TODO: what about import.sql? It gets formatted too ugly +pg_format -L -s 2 -w 100 tables.sql >tables.fmt.sql +mv tables.fmt.sql tables.sql diff --git a/sql/tables.sql b/sql/tables.sql index 9196e3c..3b135ae 100644 --- a/sql/tables.sql +++ b/sql/tables.sql @@ -13,8 +13,11 @@ -- -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . - -CREATE TABLE version( id integer PRIMARY KEY AUTOINCREMENT, version text NOT NULL, created timestamp DEFAULT CURRENT_TIMESTAMP, notes text +CREATE TABLE version ( + id integer PRIMARY KEY AUTOINCREMENT, + version text NOT NULL, + created timestamp DEFAULT CURRENT_TIMESTAMP, + notes text ); CREATE TABLE nutr_def ( @@ -44,10 +47,10 @@ CREATE TABLE food_des ( ref_desc text, refuse int, sci_name text, - n_factor FLOAT, - pro_factor FLOAT, - fat_factor FLOAT, - cho_factor FLOAT, + n_factor float, + pro_factor float, + fat_factor float, + cho_factor float, FOREIGN KEY (fdgrp_id) REFERENCES fdgrp (id) ); @@ -143,4 +146,3 @@ CREATE TABLE serving ( FOREIGN KEY (food_id) REFERENCES food_des (id), FOREIGN KEY (msre_id) REFERENCES serv_desc (id) ); - -- 2.52.0