Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable_extension does not appear to have schema_name support #6

Open
ghost opened this issue Mar 6, 2015 · 4 comments
Open

enable_extension does not appear to have schema_name support #6

ghost opened this issue Mar 6, 2015 · 4 comments
Labels

Comments

@ghost
Copy link

ghost commented Mar 6, 2015

I have a database with multiple schemas. I want to create and enable extensions in different schemas, however, only the create_extension seems to support schemas.

-- enable_extension("citext", {:schema_name=>"widgets"})
rake aborted!
ArgumentError: wrong number of arguments (2 for 1)
@baburdick
Copy link
Contributor

Per the API doc, I'm pretty sure this can be expressed in terms of create_extension:

module PgSaurus::ConnectionAdapters::PostgreSQLAdapter::ExtensionMethods
  def enable_extension(extension_name, options = {})
    options[:if_not_exists] = true
    create_extension(extension_name, options).tap { reload_type_map }
  end
end

@albertosaurus
Copy link
Contributor

@distil-brewmaster is this still a problem for you?

@Altonymous
Copy link

We haven't tested the latest code.. We ran into many other issues introduced.. for instance if we have a database default of now() or some other function it evaluates the function and stores the evaluated value as the default in the dump. Also seeing cases where the literal string NULL is being set as the default when we have the default of null set. (legacy database)

@Altonymous
Copy link

@albertosaurus, (I'm the former distil-brewmaster)

So just updated to latest in the github repo.

Here's a sample output of the functions it's adding to the db/schema.rb. Many of these which, I believe, shouldn't be dumped since they are part of citext.

create_function 'text)', :text[], <<-FUNCTION_DEFINITION.gsub(/^[ ]{4}/, '')
  SELECT pg_catalog.regexp_matches( $1::pg_catalog.text, $2::pg_catalog.text, CASE WHEN pg_catalog.strpos($3, 'c') = 0 THEN  $3 || 'i' ELSE $3 END );
FUNCTION_DEFINITION

create_function 'citext)', :text[], <<-FUNCTION_DEFINITION.gsub(/^[ ]{4}/, '')
  SELECT pg_catalog.regexp_matches( $1::pg_catalog.text, $2::pg_catalog.text, 'i' );
FUNCTION_DEFINITION

create_function 'text)', :text, <<-FUNCTION_DEFINITION.gsub(/^[ ]{4}/, '')
  SELECT pg_catalog.regexp_replace( $1::pg_catalog.text, $2::pg_catalog.text, $3, CASE WHEN pg_catalog.strpos($4, 'c') = 0 THEN  $4 || 'i' ELSE $4 END);
FUNCTION_DEFINITION

create_function 'text)', :text, <<-FUNCTION_DEFINITION.gsub(/^[ ]{4}/, '')
  SELECT pg_catalog.regexp_replace( $1::pg_catalog.text, $2::pg_catalog.text, $3, 'i');
FUNCTION_DEFINITION

create_function 'text)', :text[], <<-FUNCTION_DEFINITION.gsub(/^[ ]{4}/, '')
  SELECT pg_catalog.regexp_split_to_array( $1::pg_catalog.text, $2::pg_catalog.text, CASE WHEN pg_catalog.strpos($3, 'c') = 0 THEN  $3 || 'i' ELSE $3 END );
FUNCTION_DEFINITION

create_function 'citext)', :text[], <<-FUNCTION_DEFINITION.gsub(/^[ ]{4}/, '')
  SELECT pg_catalog.regexp_split_to_array( $1::pg_catalog.text, $2::pg_catalog.text, 'i' );
FUNCTION_DEFINITION

create_function 'text)', :SETOF text, <<-FUNCTION_DEFINITION.gsub(/^[ ]{4}/, '')
  SELECT pg_catalog.regexp_split_to_table( $1::pg_catalog.text, $2::pg_catalog.text, CASE WHEN pg_catalog.strpos($3, 'c') = 0 THEN  $3 || 'i' ELSE $3 END );
FUNCTION_DEFINITION

create_function 'citext)', :SETOF text, <<-FUNCTION_DEFINITION.gsub(/^[ ]{4}/, '')
  SELECT pg_catalog.regexp_split_to_table( $1::pg_catalog.text, $2::pg_catalog.text, 'i' );
FUNCTION_DEFINITION

create_function 'citext)', :text, <<-FUNCTION_DEFINITION.gsub(/^[ ]{4}/, '')
  SELECT pg_catalog.regexp_replace( $1::pg_catalog.text, pg_catalog.regexp_replace($2::pg_catalog.text, '([^a-zA-Z_0-9])', E'\\\\\\1', 'g'), $3::pg_catalog.ext, 'gi' );
FUNCTION_DEFINITION

create_function 'integer)', :text, <<-FUNCTION_DEFINITION.gsub(/^[ ]{4}/, '')
  SELECT (pg_catalog.regexp_split_to_array( $1::pg_catalog.text, pg_catalog.regexp_replace($2::pg_catalog.text, '([^a-zA-Z_0-9])', E'\\\\\\1', 'g'), i'))[$3];
FUNCTION_DEFINITION

create_function 'citext)', :integer, <<-FUNCTION_DEFINITION.gsub(/^[ ]{4}/, '')
  SELECT pg_catalog.strpos( pg_catalog.lower( $1::pg_catalog.text ), pg_catalog.lower( $2::pg_catalog.text ) );
FUNCTION_DEFINITION

create_function 'text)', :text, <<-FUNCTION_DEFINITION.gsub(/^[ ]{4}/, '')
  SELECT pg_catalog.translate( pg_catalog.translate( $1::pg_catalog.text, pg_catalog.lower($2::pg_catalog.text), $3), pg_catalog.upper($2::pg_catalog.text), 3);
FUNCTION_DEFINITION

create_function 'anyarray)', :anyarray, <<-FUNCTION_DEFINITION.gsub(/^[ ]{4}/, '')
  SELECT array_agg(result)
  FROM (SELECT tuple.val1 + tuple.val2 AS result
        FROM (SELECT UNNEST(arr1) AS val1
                   , UNNEST(arr2) AS val2
                   , generate_subscripts(arr1, 1) AS idx) AS tuple
        ORDER BY idx) AS inn;
FUNCTION_DEFINITION

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants