<commit_before>ALTER TABLE tenants ADD PRIMARY KEY (id);
-- ;;

CREATE TYPE tier AS ENUM ('standard', 'pro');

CREATE TABLE plan (
       id text PRIMARY KEY DEFAULT gen_random_uuid()::text,
       tenant int REFERENCES tenants (id) NOT NULL,
       tier tier DEFAULT 'standard',
       created timestamptz DEFAULT now(),
       ends timestamptz DEFAULT 'infinity',
       UNIQUE(tenant, ends)
);


-- ;;

-- Default plan
INSERT INTO plan (tenant, tier)
SELECT id, 'standard'
FROM tenants
<commit_msg>[#673] Fixed broken db constraint<commit_after>ALTER TABLE tenants ADD PRIMARY KEY (id);
-- ;;

CREATE TYPE tier AS ENUM ('standard', 'pro');

CREATE TABLE plan (
       id text PRIMARY KEY DEFAULT gen_random_uuid()::text,
       tenant int REFERENCES tenants (id) NOT NULL,
       tier tier DEFAULT 'standard',
       created timestamptz DEFAULT now(),
       ends timestamptz DEFAULT 'infinity'
);

CREATE UNIQUE INDEX plan_tenant_ends_key ON plan (tenant, ends)
WHERE ends = 'infinity';

-- ;;

-- Default plan
INSERT INTO plan (tenant, tier)
SELECT id, 'standard'
FROM tenants

{'fraction_non_alphanumeric': 0.10351201478743069, 'fraction_numerical': 0.0027726432532347504, 'mean_word_length': 3.5125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '140070', 'n_tokens_mistral': 343, 'n_tokens_neox': 324, 'n_words': 125}