diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..9786370 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,34 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-toml + - id: check-vcs-permalinks + # - id: end-of-file-fixer + - id: fix-byte-order-marker + - id: mixed-line-ending + - id: trailing-whitespace + + # - repo: https://github.com/tconbeer/sqlfmt + # rev: v0.18.0 + # hooks: + # - id: sqlfmt + # language_version: python + + - repo: https://github.com/sqlfluff/sqlfluff + rev: 3.0.3 + hooks: + - id: sqlfluff-lint + - id: sqlfluff-fix + +# - repo: https://github.com/pre-commit/mirrors-prettier +# rev: "v3.1.0" +# hooks: +# - id: prettier +# types_or: [ sql ] + +# - repo: https://github.com/doublify/pre-commit-rust +# rev: master +# hooks: +# - id: fmt +# args: ['--verbose', '--edition', '2018', '--'] diff --git a/.sqlfluff b/.sqlfluff new file mode 100644 index 0000000..698c4ec --- /dev/null +++ b/.sqlfluff @@ -0,0 +1,23 @@ +[sqlfluff] +dialect = sqlite +# exclude_rules = L016,L031,L034 + +[sqlfluff:indentation] +tab_space_size = 4 +allow_implicit_indents = True + +[sqlfluff:rules:capitalisation.keywords] +# Keywords Capitalization +capitalisation_policy = upper + +[sqlfluff:rules:capitalisation.functions] +# Function Name Capitalization +extended_capitalisation_policy = upper + +[sqlfluff:rules:capitalisation.literals] +# Null & Boolean Literals +capitalisation_policy = upper + +[sqlfluff:rules:capitalisation.types] +# Data Type Capitalization +extended_capitalisation_policy = upper diff --git a/crates/lavina-core/migrations/0000_first.sql b/crates/lavina-core/migrations/0000_first.sql new file mode 100644 index 0000000..4c28baf --- /dev/null +++ b/crates/lavina-core/migrations/0000_first.sql @@ -0,0 +1,34 @@ +CREATE TABLE users ( + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + name STRING UNIQUE NOT NULL +); + +-- for development only, replace with properly hashed passwords later +CREATE TABLE challenges_plain_password +( + user_id INTEGER PRIMARY KEY NOT NULL, + password STRING NOT NULL +); + +CREATE TABLE rooms +( + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + name STRING UNIQUE NOT NULL, + topic STRING NOT NULL, + message_count INTEGER NOT NULL DEFAULT 0 +); + +CREATE TABLE messages ( + room_id INTEGER NOT NULL, + id INTEGER NOT NULL, -- unique per room, sequential in one room + content STRING NOT NULL, + PRIMARY KEY (room_id, id) +); + +CREATE TABLE memberships +( + user_id INTEGER NOT NULL, + room_id INTEGER NOT NULL, + status INTEGER NOT NULL, -- 0 for not-joined, 1 for joined, 2 for banned + PRIMARY KEY (user_id, room_id) +); diff --git a/crates/lavina-core/migrations/0001_msg_author.sql b/crates/lavina-core/migrations/0001_msg_author.sql new file mode 100644 index 0000000..91509ea --- /dev/null +++ b/crates/lavina-core/migrations/0001_msg_author.sql @@ -0,0 +1 @@ +ALTER TABLE messages ADD author_id INTEGER NULL REFERENCES users (id); -- noqa: PRS \ No newline at end of file diff --git a/crates/lavina-core/migrations/0002_msg_timestamps_to_stored_history.sql b/crates/lavina-core/migrations/0002_msg_timestamps_to_stored_history.sql new file mode 100644 index 0000000..8ddc1d3 --- /dev/null +++ b/crates/lavina-core/migrations/0002_msg_timestamps_to_stored_history.sql @@ -0,0 +1 @@ +-- Add migration script here diff --git a/crates/lavina-core/migrations/0_first.sql b/crates/lavina-core/migrations/0_first.sql deleted file mode 100644 index 765b91d..0000000 --- a/crates/lavina-core/migrations/0_first.sql +++ /dev/null @@ -1,31 +0,0 @@ -create table users( - id integer primary key autoincrement not null, - name string unique not null -); - --- for development only, replace with properly hashed passwords later -create table challenges_plain_password( - user_id integer primary key not null, - password string not null -); - -create table rooms( - id integer primary key autoincrement not null, - name string unique not null, - topic string not null, - message_count integer not null default 0 -); - -create table messages( - room_id integer not null, - id integer not null, -- unique per room, sequential in one room - content string not null, - primary key (room_id, id) -); - -create table memberships( - user_id integer not null, - room_id integer not null, - status integer not null, -- 0 for not-joined, 1 for joined, 2 for banned - primary key (user_id, room_id) -); diff --git a/crates/lavina-core/migrations/1_msg_author.sql b/crates/lavina-core/migrations/1_msg_author.sql deleted file mode 100644 index b25146e..0000000 --- a/crates/lavina-core/migrations/1_msg_author.sql +++ /dev/null @@ -1 +0,0 @@ -alter table messages add author_id integer null references users(id);