Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Fix sqlfluff config, fix .sql files
Browse files Browse the repository at this point in the history
  • Loading branch information
4ydan committed Aug 23, 2023
1 parent 21f0028 commit 2d32ca5
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 115 deletions.
11 changes: 1 addition & 10 deletions backend/.sqlfluff
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# https://docs.sqlfluff.com/en/stable/configuration.html
[sqlfluff]
dialect = postgres

max_line_length = 120

#enforce upper and lowercase
# Capitalization Rules
[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = upper
[sqlfluff:rules:capitalisation.identifiers]
Expand All @@ -13,13 +12,5 @@ capitalisation_policy = lower
extended_capitalisation_policy = lower
[sqlfluff:rules:capitalisation.literals]
capitalisation_policy = lower

# SQLFluff doesn't support different capitalization for different types, nor multiple versions of the same rule.
# So, this is a workaround :)
# Since we decided to use snake_case for everything except database keywords,
# run 'pre-commit run sqlfluff-fix -a' twice, first with 'extended_capitalisation_policy = upper', then with the other two lines.
[sqlfluff:rules:capitalisation.types]
#extended_capitalisation_policy = upper

extended_capitalisation_policy = lower
ignore_words = text, integer, boolean, smallint, geography, date, real, uuid, timestamp, double, precision, regclass, void, trigger
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- This file was automatically created by Diesel to setup helper functions
-- and other internal bookkeeping.

DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl REGCLASS);
DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
DROP FUNCTION IF EXISTS diesel_set_updated_at();
6 changes: 3 additions & 3 deletions backend/migrations/00000000000000_diesel_initial_setup/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
-- SELECT diesel_manage_updated_at('users');
-- ```
CREATE OR REPLACE FUNCTION diesel_manage_updated_at(
_tbl REGCLASS
) RETURNS VOID AS $$
_tbl regclass
) RETURNS void AS $$
BEGIN
EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
END;
$$ LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS TRIGGER AS $$
CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
BEGIN
IF (
NEW IS DISTINCT FROM OLD AND
Expand Down
152 changes: 76 additions & 76 deletions backend/migrations/2023-07-01-152628_squashed_setup/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -176,68 +176,68 @@ END;
$$;

CREATE TABLE layers (
id INTEGER NOT NULL,
map_id INTEGER NOT NULL,
id integer NOT NULL,
map_id integer NOT NULL,
type layer_type NOT NULL,
name TEXT NOT NULL,
is_alternative BOOLEAN NOT NULL
name text NOT NULL,
is_alternative boolean NOT NULL
);

CREATE SEQUENCE layers_id_seq
AS INTEGER
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;

CREATE TABLE maps (
id INTEGER NOT NULL,
name TEXT NOT NULL,
creation_date DATE NOT NULL,
deletion_date DATE,
last_visit DATE,
is_inactive BOOLEAN NOT NULL,
zoom_factor SMALLINT NOT NULL,
honors SMALLINT NOT NULL,
visits SMALLINT NOT NULL,
harvested SMALLINT NOT NULL,
id integer NOT NULL,
name text NOT NULL,
creation_date date NOT NULL,
deletion_date date,
last_visit date,
is_inactive boolean NOT NULL,
zoom_factor smallint NOT NULL,
honors smallint NOT NULL,
visits smallint NOT NULL,
harvested smallint NOT NULL,
privacy privacy_option NOT NULL,
description TEXT,
description text,
location GEOGRAPHY (POINT, 4326),
owner_id UUID NOT NULL
owner_id uuid NOT NULL
);

CREATE SEQUENCE maps_id_seq
AS INTEGER
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;

CREATE TABLE plants (
id INTEGER NOT NULL,
unique_name TEXT NOT NULL,
common_name_en TEXT [],
common_name_de TEXT [],
family TEXT,
id integer NOT NULL,
unique_name text NOT NULL,
common_name_en text [],
common_name_de text [],
family text,
--genus text,
edible_uses_en TEXT,
edible_uses_en text,
--medicinal_uses text,
--material_uses_and_functions text,
--botanic text,
--material_uses text,
functions TEXT,
heat_zone SMALLINT,
functions text,
heat_zone smallint,
shade shade,
soil_ph soil_ph [],
soil_texture soil_texture [],
--soil_water_retention soil_water_retention[],
--environmental_tolerances text[],
--native_geographical_range text,
--native_environment text,
ecosystem_niche TEXT,
ecosystem_niche text,
deciduous_or_evergreen deciduous_or_evergreen,
herbaceous_or_woody herbaceous_or_woody,
life_cycle life_cycle [],
Expand All @@ -246,23 +246,23 @@ CREATE TABLE plants (
fertility fertility [],
--flower_colour text,
--flower_type flower_type,
created_at TIMESTAMP without time zone DEFAULT now() NOT NULL,
updated_at TIMESTAMP without time zone DEFAULT now() NOT NULL,
has_drought_tolerance BOOLEAN,
tolerates_wind BOOLEAN,
created_at timestamp without time zone DEFAULT now() NOT NULL,
updated_at timestamp without time zone DEFAULT now() NOT NULL,
has_drought_tolerance boolean,
tolerates_wind boolean,
--plant_references text[],
--is_tree boolean,
--nutrition_demand nutrition_demand,
preferable_permaculture_zone SMALLINT,
preferable_permaculture_zone smallint,
--article_last_modified_at timestamp without time zone,
hardiness_zone TEXT,
hardiness_zone text,
light_requirement light_requirement [],
water_requirement water_requirement [],
propagation_method propagation_method [],
alternate_name TEXT,
alternate_name text,
--diseases text,
edible BOOLEAN,
edible_parts TEXT [],
edible boolean,
edible_parts text [],
--germination_temperature text,
--introduced_into text,
--habitus text,
Expand All @@ -280,7 +280,7 @@ CREATE TABLE plants (
--slug text,
spread plant_spread,
--utility text,
warning TEXT,
warning text,
--when_to_plant_cuttings_en text,
--when_to_plant_division_en text,
--when_to_plant_transplant_en text,
Expand All @@ -296,7 +296,7 @@ CREATE TABLE plants (
--wikipedia_url text,
--days_to_maturity text,
--pests text,
version SMALLINT,
version smallint,
--germination_time text,
--description text,
--parent_id text,
Expand All @@ -307,15 +307,15 @@ CREATE TABLE plants (
--external_article_number text,
--external_portion_content text,
--sowing_outdoors_de text,
sowing_outdoors SMALLINT [],
harvest_time SMALLINT [],
sowing_outdoors smallint [],
harvest_time smallint [],
--spacing_de text,
--required_quantity_of_seeds_de text,
--required_quantity_of_seeds_en text,
--seed_planting_depth_de text,
--seed_weight_1000_de text,
--seed_weight_1000_en text,
seed_weight_1000 DOUBLE PRECISION,
seed_weight_1000 double precision,
--machine_cultivation_possible boolean,
--edible_uses_de text,
CONSTRAINT plant_detail_heat_zone_check CHECK (
Expand All @@ -325,85 +325,85 @@ CREATE TABLE plants (
(
(preferable_permaculture_zone IS NULL)
OR (
(preferable_permaculture_zone >= '-1'::INTEGER)
(preferable_permaculture_zone >= '-1'::integer)
AND (preferable_permaculture_zone <= 6)
)
)
)
);

CREATE SEQUENCE plant_detail_id_seq
AS INTEGER
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;

CREATE TABLE plantings (
id UUID NOT NULL,
layer_id INTEGER NOT NULL,
plant_id INTEGER NOT NULL,
x INTEGER NOT NULL,
y INTEGER NOT NULL,
width INTEGER NOT NULL,
height INTEGER NOT NULL,
rotation REAL NOT NULL,
scale_x REAL NOT NULL,
scale_y REAL NOT NULL,
add_date DATE,
remove_date DATE
id uuid NOT NULL,
layer_id integer NOT NULL,
plant_id integer NOT NULL,
x integer NOT NULL,
y integer NOT NULL,
width integer NOT NULL,
height integer NOT NULL,
rotation real NOT NULL,
scale_x real NOT NULL,
scale_y real NOT NULL,
add_date date,
remove_date date
--create_date date DEFAULT CURRENT_DATE NOT NULL,
--delete_date date
);

CREATE TABLE relations (
plant1 INTEGER NOT NULL,
plant2 INTEGER NOT NULL,
plant1 integer NOT NULL,
plant2 integer NOT NULL,
relation relation_type NOT NULL,
note TEXT
note text
);

CREATE TABLE seeds (
id INTEGER NOT NULL,
name TEXT NOT NULL,
harvest_year SMALLINT NOT NULL,
use_by DATE,
origin TEXT,
taste TEXT,
yield TEXT,
id integer NOT NULL,
name text NOT NULL,
harvest_year smallint NOT NULL,
use_by date,
origin text,
taste text,
yield text,
quantity quantity NOT NULL,
quality quality,
price SMALLINT,
generation SMALLINT,
notes TEXT,
variety TEXT,
plant_id INTEGER,
owner_id UUID NOT NULL
price smallint,
generation smallint,
notes text,
variety text,
plant_id integer,
owner_id uuid NOT NULL
);

CREATE SEQUENCE seeds_id_seq
AS INTEGER
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;

ALTER TABLE ONLY layers ALTER COLUMN id SET DEFAULT nextval(
'layers_id_seq'::REGCLASS
'layers_id_seq'::regclass
);

ALTER TABLE ONLY maps ALTER COLUMN id SET DEFAULT nextval(
'maps_id_seq'::REGCLASS
'maps_id_seq'::regclass
);

ALTER TABLE ONLY plants ALTER COLUMN id SET DEFAULT nextval(
'plant_detail_id_seq'::REGCLASS
'plant_detail_id_seq'::regclass
);

ALTER TABLE ONLY seeds ALTER COLUMN id SET DEFAULT nextval(
'seeds_id_seq'::REGCLASS
'seeds_id_seq'::regclass
);

ALTER TABLE ONLY layers
Expand Down
10 changes: 5 additions & 5 deletions backend/migrations/2023-07-04-190000_base_layer/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
-- Please create a new migration instead.

CREATE TABLE base_layer_images (
id UUID PRIMARY KEY,
layer_id INTEGER NOT NULL,
path TEXT NOT NULL,
rotation REAL NOT NULL,
scale REAL NOT NULL,
id uuid PRIMARY KEY,
layer_id integer NOT NULL,
path text NOT NULL,
rotation real NOT NULL,
scale real NOT NULL,
FOREIGN KEY (layer_id) REFERENCES layers (id) ON DELETE CASCADE
);
18 changes: 9 additions & 9 deletions backend/migrations/2023-07-12-143111_user_data/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ CREATE TYPE membership AS ENUM (
);

CREATE TABLE users (
id UUID PRIMARY KEY,
id uuid PRIMARY KEY,
salutation salutation NOT NULL,
title TEXT,
country TEXT NOT NULL,
phone TEXT,
website TEXT,
organization TEXT,
title text,
country text NOT NULL,
phone text,
website text,
organization text,
experience experience,
membership membership,
member_years INTEGER ARRAY,
member_since DATE,
permacoins INTEGER ARRAY
member_years integer ARRAY,
member_since date,
permacoins integer ARRAY
);
Loading

0 comments on commit 2d32ca5

Please sign in to comment.