text: -- +goose Up
  CREATE TABLE histories (id INT PRIMARY KEY, created_at DATE);
  
  -- +goose StatementBegin
  CREATE OR REPLACE FUNCTION histories_partition_creation( DATE, DATE )
  returns void AS $$
  DECLARE
    create_query text;
  BEGIN
    FOR create_query IN SELECT
        'CREATE TABLE IF NOT EXISTS histories_'
        || TO_CHAR( d, 'YYYY_MM' )
        || ' ( CHECK( created_at >= timestamp '''
        || TO_CHAR( d, 'YYYY-MM-DD 00:00:00' )
        || ''' AND created_at < timestamp '''
        || TO_CHAR( d + INTERVAL '1 month', 'YYYY-MM-DD 00:00:00' )
        || ''' ) ) inherits ( histories );'
      FROM generate_series( $1, $2, '1 month' ) AS d
    LOOP
      EXECUTE create_query;
    END LOOP;  -- LOOP END
  END;         -- FUNCTION END
  $$
  language plpgsql;
  -- +goose StatementEnd
  
  
  -- +goose Down
  DROP FUNCTION IF EXISTS histories_partition_creation( DATE, DATE );
  DROP TABLE IF EXISTS histories CASCADE;