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

support views in structure_load #956

Open
jonahgeorge opened this issue Nov 28, 2021 · 0 comments
Open

support views in structure_load #956

jonahgeorge opened this issue Nov 28, 2021 · 0 comments

Comments

@jonahgeorge
Copy link
Contributor

jonahgeorge commented Nov 28, 2021

Issue

Given an example schema:

create table posts
(
    ID   int identity,
    Body varchar(max) not null,
)
go

create view popular_posts
as
select *
from posts

structure_dump generates the following file (which strips the Go statements added in between the various objects).

	/* The object 'dbo.posts' does not have any indexes, or you do not have permissions. */
	/* No constraints are defined on object 'dbo.posts', or you do not have permissions. */
	/* No foreign keys reference table 'dbo.posts', or you do not have permissions on referencing tables. */
	/* No views with schema binding reference table 'dbo.posts'. */

CREATE TABLE dbo.posts
	( ID   int             NOT NULL
	, Body varchar(-1)     NOT NULL
	)



CREATE VIEW popular_posts
AS
SELECT *
FROM posts

As a result, when loading the objects back into the database via structure_load, the following error is thrown.

$ rails db:setup
...
rails aborted!
ActiveRecord::StatementInvalid: TinyTds::Error: 'CREATE VIEW' must be the first statement in a query batch.
/Users/jonahgeorge/src/funcard/funcard/bin/rails:5:in `<top (required)>'
/Users/jonahgeorge/src/funcard/funcard/bin/spring:10:in `block in <top (required)>'
/Users/jonahgeorge/src/funcard/funcard/bin/spring:7:in `<top (required)>'

Expected behavior

structure_load should be capable of loading a structure.sql file generated by structure_dump.

Actual behavior

TinyTds::Error: 'CREATE VIEW' must be the first statement in a query batch. exception is raised.

Details

  • Rails version: 6.1.4
  • SQL Server adapter version: v6.1.2.1
  • FreeTDS details:
$ tsql -C    
Compile-time settings (established with the "configure" script)
                           Version: freetds v1.3.3
            freetds.conf directory: /opt/homebrew/etc
    MS db-lib source compatibility: no
       Sybase binary compatibility: yes
                     Thread safety: yes
                     iconv library: yes
                       TDS version: 7.3
                             iODBC: no
                          unixodbc: yes
             SSPI "trusted" logins: no
                          Kerberos: yes
                           OpenSSL: yes
                            GnuTLS: no
                              MARS: yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant