Coder Social home page Coder Social logo

schema_plus_views's Issues

Views should follow tables in schema.rb

This is a great gem, I use it all the time.

When schema.rb is created, the SQL view is inserted in alpha order. This means that if there is a later table in the schema.rb file which the view depends on, rake db:reset will fail as the dependent object is not created when the create_view is called.

The workaround is to manually edit the schema.rb file after any migrations are run, and move the views down.

Any suggestions on how to automate this? It could be further complicated if views depend on views, but if all the views we added to schema.rb after all the tables, it would solve 90% of the problems.

[PG] Created View in Wrong Schema

Currently the view's are being created in the schema that matches my username, and not in the public schema where the rest of my rails data is location.

Create Views in database with each column on a separate line shows up with /n in schema

In the database schema, the view looks like this:

CREATE OR REPLACE VIEW usersx AS
SELECT users.id,
users.client_id,
users.username,
users.firstname

With the schema_plus_views gem, the schema.rb looks like this:

CREATE OR REPLACE VIEW usersx AS
SELECT users.id,\n users.client_id,\n users.usernam\n, users.firstname\n ...

postgresql
rake 10.4.2
rails 4.2.0
ruby 2.2.1p85
osx yosemite

Unnecessary modules within ActiveRecord namespace

If project doesn't have mysql2 loaded it creates Mysql2Adapter as a module and causes issues

>> ActiveRecord::ConnectionAdapters::Mysql2Adapter
SchemaPlus::Views::ActiveRecord::ConnectionAdapters::Mysql2Adapter

In projects that have mysql2 it works correctly:

>> ActiveRecord::ConnectionAdapters::Mysql2Adapter
ActiveRecord::ConnectionAdapters::Mysql2Adapter < ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter

to_json

just for my information. why do you use method to_json in this place?

class View < KeyStruct[:name, :definition]
   def assemble(stream)
        heredelim = "END_VIEW_#{name.upcase}"
        stream.puts "  create_view #{name.to_json}, <<-#{heredelim}, :force => true\n"
        definition.split("\n").each { |line| stream.puts line.to_json[1...-1] + "\n" }
        stream.puts "  #{heredelim}\n\n"
    end
end

if view contains fields from an json column in pg table in schema db i get unicode lines like that

 ((details -\u003e\u003e 'cost'::text))::numeric(10,2) AS cost

Views with multi-schema joins in postgres

I have an issue when defining views with joins between two postgres schemas (e.g. public and client_a).

Suppose we have this view definition:

CREATE VIEW my_view AS SELECT plans.name, clients.id
FROM clients 
JOIN public.plans ON plans.id = clients.plan_id

Then then the following SQL is stored in db/schema.rb (notice missing public prefix for plans):

SELECT plans.name, clients.id
FROM clients 
JOIN plans ON plans.id = clients.plan_id

I'm using this in combination with the apartment gem which loads schema.rb file for every tenant it creates. It also creates all tables for every schema/tenant, even if they are only used in the public schema.

The query to get the views:

SELECT pg_get_viewdef(oid)
FROM pg_class
WHERE relkind = 'v'
AND relname = '#{view_name}'

Not sure how to proceed yet. The views generated by migrations are correct.
Basically I want the "exluded model tables" from apartment to be prefixed with public in the db/schema.rb while the others use search_path.

How to exclude postgis views when run db:setup command

I am using postgis, when I setup by schme.rb will throwing following error:

ActiveRecord::StatementInvalid: PG::DependentObjectsStillExist: ERROR:  cannot drop view raster_columns because extension postgis requires it

I do not wanna to drop the postgis views

Table not added to schema under circumstances to be determined [edit 2016-06-16]

ACTUAL BEHAVIOR
without schema_plus_views gem

create a migration to create table users if you don't have one
or
create any test migration for a different table (not users) if you already have users
rake db:migrate
create users... added to schema (or still there if it was already there)
create a migration for usersx view
rake db:migrate
users table still in schema
usersx view is not added to schema (standard rake behavior)

add schema_plus_views gem to gemfile
bundle
create any test migration for a different table
rake db:migrate
create view usersx... added to schema as expected with gem
create users table... not in schema

EXPECTED BEHAVIOR
create view usersx in schema
create table users in schema

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.