grate-devs / grate-devs/grate

Custom create database scripts seem to break grate

Open
#629 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
297
Forks
55
Avg merge
18m
Merged PRs (30d)
1

Description

**Describe the bug**
Custom create database scripts seem to break grate.

Grate fails to log in to the database after it has run the database creation script, even though the database IS created, and has the expected user mappings (SQL Server). If you run grate again, it successfully logs in and continues migrating.

I have tried on multiple machines, and with both Trusted_Connection and SQL Server auth (username+password).

This worked in RoundhousE, which is what we are migrating from.

Grate has no issues logging in to newly created DBs when using the default create database functionality (e.g. no custom script), so I'm assuming the root issue is somewhere in the code path for custom create DB scripts.

**To Reproduce**
See repository for minimal example:
https://github.com/franzvrolijk-if/grate_bug_2025_04

1. Run grate with a connection string in a folder containing `createDatabase/createDatabase.sql`. The creation script can be the same as grate uses by default which seems to be a simple `CREATE DATABASE $databaseName`.

**Expected behavior**
I would expect grate to create the DB using my script, then continue with migrations on the newly created database.

**Logs**
```
Initializing connections.
Running grate v1.8.0 (build date 07/25/2024 09:13:32) against . - grate_bug_2025_04.
Looking in . for scripts to run.
================================================================================
Setup, Backup, Create/Restore/Drop
================================================================================
Running 'createDatabase.sql'.
================================================================================
Grate Structure
================================================================================
An error occurred: Cannot open database "grate_bug_2025_04" requested by the login. The login failed.
Login failed for user '(redacted)'.
```

**Desktop (please complete the following information):**
- OS: Windows 10, 64-bit
- grate version: 1.8.0.0 (I did try a couple of previous releases as well)
- Database: Microsoft SQL Server Developer (64-bit), 16.0.1135.2

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.