Merge branch 'main' of ssh://localhost:3322/9pfs/countify
All checks were successful
Run node --check on everything / node-check (push) Successful in 7s
Check project using prettier / prettier (push) Successful in 24s
Make sure the server is actually able to start / boot-test (push) Successful in 48s

This commit is contained in:
9pfs 2024-05-25 04:15:51 +00:00
commit 6648294566
Signed by: 9pfs
SSH key fingerprint: SHA256:TOcGxMQCfy4VvRM8AzgXErKXdkAtaTcpGXgYMpyoJoY
3 changed files with 20 additions and 2 deletions

View file

@ -5,8 +5,8 @@ CREATE TABLE IF NOT EXISTS namespaces(
);
CREATE TABLE IF NOT EXISTS keys(
id SERIAL PRIMARY KEY,
namespace_id INTEGER REFERENCES namespaces (id) ON DELETE RESTRICT,
name TEXT UNIQUE NOT NULL,
namespace_id INTEGER REFERENCES namespaces (id) ON DELETE RESTRICT NOT NULL,
name TEXT NOT NULL,
-- Someone might want to store huge numbers in here, so... why not?
value BIGINT NOT NULL DEFAULT 0,
enable_reset BOOLEAN NOT NULL DEFAULT TRUE,

View file

@ -0,0 +1,10 @@
-- 0002-no-globally-unique-keys.sql
-- This makes keys with the same name be able to exist in different namespaces, while still preventing duplicates in the same namespace.
BEGIN;
-- Delete the "unique" constraint
ALTER TABLE keys DROP CONSTRAINT IF EXISTS keys_name_key;
-- Avoid duplicate constraints.
ALTER TABLE keys DROP CONSTRAINT IF EXISTS keys_name_namespace_id_key;
-- Make sure that name and namespace_id together still have to be unique
ALTER TABLE keys ADD UNIQUE (name, namespace_id);
COMMIT;

View file

@ -0,0 +1,8 @@
-- Make sure that keys.namespace_id isn't able to be null
BEGIN;
-- Remove all null keys.namespace_id values. Nuking data like this is reckless, but it's the only option.
DROP FROM keys WHERE namespace_id = NULL;
-- Delete before adding to avoid conflicts
ALTER TABLE keys ALTER COLUMN namespace_id DROP NOT NULL;
ALTER TABLE keys ALTER COLUMN namespace_id SET NOT NULL;
COMMIT;