Merge branch 'main' of ssh://localhost:3322/9pfs/countify
This commit is contained in:
commit
6648294566
3 changed files with 20 additions and 2 deletions
|
@ -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,
|
||||
|
|
10
migrations/0002-no-globally-unique-keys.sql
Normal file
10
migrations/0002-no-globally-unique-keys.sql
Normal 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;
|
8
migrations/0003-keys-namespace-id-not-null.sql
Normal file
8
migrations/0003-keys-namespace-id-not-null.sql
Normal 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;
|
Loading…
Reference in a new issue