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

SqlServer error when a schema is set #181

Open
jonathanbp opened this issue Jun 19, 2020 · 0 comments
Open

SqlServer error when a schema is set #181

jonathanbp opened this issue Jun 19, 2020 · 0 comments

Comments

@jonathanbp
Copy link

Hello

I'm using SqlServer 2017. When I set a schema via .SetSchema(...) I get an error;

mssql: Incorrect syntax near the keyword 'schema'

The sql produced for creating the table by sql-migrate when using schema [internal] and table [migrations] is as follows;

if not exists (select name from sys.schemas where name = '[internal]') create schema [internal];if not exists (select * from information_schema.tables where table_schema = '[internal]' and table_name = '[migrations]') create table [internal].[migrations] (\"id\" varchar(255) not null primary key, \"applied_at\" datetime) ;

It seems the create schema part must be executed in its own batch; https://stackoverflow.com/questions/5748056/why-cant-i-use-create-schema-in-a-begin-end-block-in-sql-management-studio which also works for me elsewhere. The sql statement would then be

if not exists (select name from sys.schemas where name = '[internal]') exec ('create schema [internal]');if not exists (select * from information_schema.tables where table_schema = '[internal]' and table_name = '[migrations]') create table [internal].[migrations] (\"id\" varchar(255) not null primary key, \"applied_at\" datetime) ;

which works when running it manually.

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

No branches or pull requests

1 participant