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

sqlsrv (MSSQL) support. #390

Open
ilexei opened this issue Jan 3, 2025 · 0 comments
Open

sqlsrv (MSSQL) support. #390

ilexei opened this issue Jan 3, 2025 · 0 comments

Comments

@ilexei
Copy link

ilexei commented Jan 3, 2025

In database.php there is a section, describing MS SQL server connection

        'pgsql' => [
            'driver' => 'pgsql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
            'schema' => 'public',
            'sslmode' => 'prefer',
        ],

I tested the connection and there are some issues with that.

  1. The sqlsrv driver is not installed in the docker
    It could be fixed like this
RUN apt-get update && apt-get install -y gnupg2
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 
RUN curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list 

RUN apt-get update 
RUN ACCEPT_EULA=Y apt-get -y --no-install-recommends install msodbcsql17 unixodbc-dev 
RUN pecl install sqlsrv
RUN pecl install pdo_sqlsrv
RUN docker-php-ext-enable sqlsrv pdo_sqlsrv

I verified it but did not optimize: maybe another version of ubuntu should be set or some packages were installed previously.
2. In some queries the collation is hardcoded
collation('utf8mb4_bin')
This type of collation is not supported by MS SQL, so the easy way is to redefine it with
DB_COLLATION env var or use it from the connection.
3. The SQL syntax
ALTER TABLE .* MODIFY is not supported in the MS SQL. So, the migrations fail on this step. As a work-around I replaced MODIFY with env('SPECIAL_MODIFY', 'MODIFY'), but it looks hacky. Then I can pass ALTER COLUMN as SPECIAL_MODIFY.
4. The last thing, which blocked me completely, is again ALTER TABLE
"ALTER TABLE lessons MODIFY raw_text MEDIUMBLOB". Unfortunately, even if the table is empty, MS SQL cannot change the column type.
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Implicit conversion from data type nvarchar(max) to varbinary(max) is not allowed. Use the CONVERT function to run this query.
I stuck here, unfortunately.
So, this is "feature request" I assume. Or, if there are any suggestions on overcoming the problem - I'm ready to test it!

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