Comments (3)
Thanks for taking an interest. Fixing this should be a "simple matter" of fiddling the regex to properly parse the square brackets, and doing something so that the assemble
method will close the square brackets.
That said, I imagine that many other things are likely broken for SQL Server -- SQL Server isn't one of the "officially supported" DBMS's. That's mostly because development of the SchemaPlus family happens on OS X/linux with testing on travis-ci, and so Sql Server isn't a convenient option. If you'd like to dive into setting things up to support SQL Server, I'm not opposed. But it wouldn't be a trivial task: you'd need to set up, say, Appveyor to run the test suite on Sql Server while travis runs the others, and ideally also set up some reasonably convenient mechanism for OS X/Linux developers to be able to test while developing. And of course add all the necessary SQL Server-specific stuff to schema_plus_core. If you're interested in doing all that, I'm happy to discuss it further.
And to answer your other questions: The reason that schema_plus/core/active_record/connection_adapters/abstract_adapter.rb#L47 splits up the query only to assemble it again, is that it's setting up a "middleware stack" that other gems can tap into. That is, schema_plus_core splits up the query into component parts, other gems can examine and possibly modify those components, and at the end of the stack execution schema_plus_core reassembles the resulting query. (E.g. schema_plus/foreign_keys/middleware/sql.rb#L13 adds some terms to the body.) The underlying idea--for all of schema_plus_core--is to put all the ugly hacky dbms-specific and rails-version-specific stuff in schema_plus_core, providing a reasonably clean, simple, and stable interface for other gems to use.
from schema_plus.
Thanks for your response @ronen. The reasoning makes sense now that you mention it.
I've determined that the following works (at least for the specific error I was getting).
There have been three changes made:
- The
END_BRACKET_MAPPING
provides mappings for the end quote - The regex in the
parse!
method explicitly checks for[
and]
- The
assemble
method uses theEND_BRACKET_MAPPING
to determine the correct end quote to use
module SchemaPlus
module Core
module SqlStruct
IndexComponents = KeyStruct[:name, :type, :columns, :options, :algorithm, :using]
class Table < KeyStruct[:command, :name, :body, :options, :quotechar, :inheritance]
INHERITANCE_REGEX = %r{ \s* (?<inheritance>INHERITS \s* \( [^)]* \)) }mxi
END_BRACKET_MAPPING = {?' => ?', ?" => ?", ?` => ?`, ?[ => ?]}
def parse!(sql)
m = sql.strip.match %r{
\A
(?<command>.*\bTABLE\b) \s*
((?<quote>['"`])(?<name>\S+)\k<quote>|(?<quote>[\[])(?<name>\S+)\]) \s*
\( \s*
(?<body>.*) \s*
\) \s*
# can't use optional ? for inheritance because it would be greedily grabbed into body;
# ideally this would use an actual parser rather than regex
#{INHERITANCE_REGEX if sql.match INHERITANCE_REGEX}
(?<options> \S.*)?
\Z
}mxi
self.command = m[:command]
self.quotechar = m[:quote]
self.name = m[:name]
self.body = m[:body]
self.options = m[:options]
self.inheritance = m[:inheritance] rescue nil
end
def assemble
["#{command} #{quotechar}#{name}#{END_BRACKET_MAPPING[quotechar]} (#{body})", inheritance, options].reject(&:blank?).join(" ")
end
end
end
end
end
Am I right by assuming that a pull request with this change wouldn't get accept without support for running tests in a SQL Server environment? If it will get accepted I'll submit the commit.
Unfortunately I'm not confident that I can commit to implementing a solution for all SQL Server issues, however, I would be keen to run the test suit to see what issues there are. How do I get the tests running for schema_plus_core
?
The other issue I see with implementing a complete SQL Server solution is that each of the schema_plus extension gems would require a similar separate testing environment.
from schema_plus.
@brent-clintel your fix does look good. But you're right, without a test suite for SQL Server I wouldn't want to accept a PR for it.
For info on running the test suite, see the Development & Testing section of the schema_plus_core README. The quick answer is you run $ bundle exec schema_dev rspec
which sets things up to run the specs on any/all combinations of db, rails, and ruby version that the testing is configured for. Of course it won't set things up for SQL Server -- but you can run $ bundle exec schema_dev -n rspec
and see the detailed commands it would run, and pattern match on that.
...and that gives the hint to your question about setting up the testing environment for each gem in the schema_plus family: schema_dev takes care of setting everything up, based on a file schema_dev.yml
in each gem's root. So the way to go about adding SQL Server support would be to add it to schema_dev.
from schema_plus.
Related Issues (20)
- Thread safety problem with schema_plus 2 / Postgres HOT 8
- Wrong index export in jsonb column HOT 2
- change_column uses default foreign key configuration instead of defined configuration causing migration to crash HOT 1
- schema_plus 1.8.x: jruby + postgresql with activerecord-jdbcpostgresql-adpater > 1.3.14 HOT 2
- When using add_column foreign key does not use the default_name method HOT 3
- Schema dump support for multiple schemas HOT 6
- doesn't work with annotate gem and MySQL and postgres
- Index name not respected when adding an index in `change_table` HOT 2
- Schema plus schema dump crashes on custom types on postgresql HOT 5
- Bug: Postgres expression index with multiple expressions runs correct SQL, but produces incorrect schema modifications HOT 2
- add_foreign_key not compatible with Activerecord version HOT 1
- All but the last `t.index` reference for a table are ignored HOT 4
- Wrong foreign_key format in schema.rb HOT 5
- Support Rails 5 HOT 9
- Issue when upgrading from Rails 4.2.5.2 to 4.2.6 HOT 5
- Upgrade from 2.0.0 to 2.0.1 alters schema.db file format HOT 8
- New gem request: Support arbitrary per-table and/or per-column metadata in schema
- Support ruby +2.1 HOT 2
- nal has_many
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from schema_plus.