<commit_before>--
-- This is a Media Cloud PostgreSQL schema difference file (a "diff") between schema
-- versions 4464 and 4465.
--
-- If you are running Media Cloud with a database that was set up with a schema version
-- 4464, and you would like to upgrade both the Media Cloud and the
-- database to be at version 4465, import this SQL file:
--
--     psql mediacloud < mediawords-4464-4465.sql
--
-- You might need to import some additional schema diff files to reach the desired version.
--

--
-- 1 of 2. Import the output of 'apgdiff':
--

SET search_path = public, pg_catalog;


ALTER TABLE downloads
    DROP CONSTRAINT downloads_feed_id_valid;
ALTER TABLE downloads
    ADD CONSTRAINT downloads_feed_id_valid check (feeds_id is not null);

ALTER TABLE downloads
    DROP CONSTRAINT downloads_story;
ALTER TABLE downloads
    ADD CONSTRAINT downloads_story check (((type = 'feed') and stories_id is null) or (stories_id is not null));

DROP INDEX downloads_spider_urls;
DROP INDEX downloads_spider_download_errors_to_clear;
DROP INDEX downloads_queued_spider;


CREATE OR REPLACE FUNCTION set_database_schema_version() RETURNS boolean AS $$
DECLARE
    
    -- Database schema version number (same as a SVN revision number)
    -- Increase it by 1 if you make major database schema changes.
    MEDIACLOUD_DATABASE_SCHEMA_VERSION CONSTANT INT := 4465;
    
BEGIN

    -- Update / set database schema version
    DELETE FROM database_variables WHERE name = 'database-schema-version';
    INSERT INTO database_variables (name, value) VALUES ('database-schema-version', MEDIACLOUD_DATABASE_SCHEMA_VERSION::int);

    return true;
    
END;
$$
LANGUAGE 'plpgsql';<commit_msg>In the SQL migration, update "download_type" enum (remove obsolete values)<commit_after>--
-- This is a Media Cloud PostgreSQL schema difference file (a "diff") between schema
-- versions 4464 and 4465.
--
-- If you are running Media Cloud with a database that was set up with a schema version
-- 4464, and you would like to upgrade both the Media Cloud and the
-- database to be at version 4465, import this SQL file:
--
--     psql mediacloud < mediawords-4464-4465.sql
--
-- You might need to import some additional schema diff files to reach the desired version.
--

--
-- 1 of 2. Import the output of 'apgdiff':
--

SET search_path = public, pg_catalog;

-- Update constraints to not include obsolete enum values
ALTER TABLE downloads
    DROP CONSTRAINT downloads_feed_id_valid;
ALTER TABLE downloads
    ADD CONSTRAINT downloads_feed_id_valid check (feeds_id is not null);

ALTER TABLE downloads
    DROP CONSTRAINT downloads_story;
ALTER TABLE downloads
    ADD CONSTRAINT downloads_story check (((type = 'feed') and stories_id is null) or (stories_id is not null));

-- Drop obsolete indices
DROP INDEX downloads_spider_urls;
DROP INDEX downloads_spider_download_errors_to_clear;
DROP INDEX downloads_queued_spider;

-- Remove old values from "download_type" enum
ALTER TYPE download_type
    RENAME TO download_type_before_removing_spider;
CREATE TYPE download_type AS ENUM ('Calais', 'calais', 'content', 'feed');
ALTER TABLE downloads
    ALTER COLUMN type TYPE download_type USING type::text::download_type;
DROP TYPE download_type_before_removing_spider;


CREATE OR REPLACE FUNCTION set_database_schema_version() RETURNS boolean AS $$
DECLARE
    
    -- Database schema version number (same as a SVN revision number)
    -- Increase it by 1 if you make major database schema changes.
    MEDIACLOUD_DATABASE_SCHEMA_VERSION CONSTANT INT := 4465;
    
BEGIN

    -- Update / set database schema version
    DELETE FROM database_variables WHERE name = 'database-schema-version';
    INSERT INTO database_variables (name, value) VALUES ('database-schema-version', MEDIACLOUD_DATABASE_SCHEMA_VERSION::int);

    return true;
    
END;
$$
LANGUAGE 'plpgsql';
{'fraction_non_alphanumeric': 0.06910885944401143, 'fraction_numerical': 0.01610808002078462, 'mean_word_length': 4.092592592592593, 'pattern_counts': {'":': 0, '<': 5, '<?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': 33, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5512285', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1115, 'n_words': 447}