Skip to content

Commit

Permalink
Update database collation to MSSQL 2019 UTF-8.
Browse files Browse the repository at this point in the history
This change sets MSSQL 2019 as the minimum SQL Server version.
For older versions, the collation can be reverted to
`SQL_Latin1_General_CP1_CI_AS` by modifying the `import.ps1` script.
However, UTF-8 compatibility is required for proper functionality.

UTF-8 ensures consistent behavior regardless of the host system's
settings. On Unix, UTF-8 is typically enabled by default. On Windows,
it can be enabled under Region settings with "Beta: Use Unicode UTF-8
for worldwide language support."

For details, see this discussion:
ko4life-net/ko#260 (comment)
  • Loading branch information
stevewgr committed Nov 19, 2024
1 parent a738c1e commit 1d61989
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Brief explanation of the directory structure under `src`:
### Prerequisite

- Being able to run powershell scripts. Note that if you're unable to run the scripts, it is because you need to allow powershell scripts to run on your system by setting the execution policy to bypass with the following powershell command: `Set-ExecutionPolicy Bypass -Scope CurrentUser`
- Microsoft SQL Server Express or Developer (confirmed to be working with versions 2022 and 2008)
- Microsoft SQL Server Express or Developer (confirmed to be working with versions 2022, minimum required 2019)
- [SQL Server](https://www.microsoft.com/en-us/sql-server/sql-server-downloads)
- [SQL Management Studio](https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms)
- [Git](https://git-scm.com/download/win) (version 2.45.1 at the time of writing)
Expand Down Expand Up @@ -45,7 +45,7 @@ During development we only create migration scripts to alter the current state o

Every migration script will be prefixed with max 4 leading zeros. For example, `0001_insert_steve_user.sql` will contain an insert statement into `TB_USER` table.

Apart from the benifit of having the database under version control, this also makes it easy to use any SQL version you want. I use both 2008 and 2022 and it works perfectly fine with both.
Apart from the benifit of having the database under version control, this also makes it easy to use any SQL version you want.

Release process should follow for every release we create in the [main ko project](https://github.com/ko4life-net/ko). The steps should look like this:
- Main ko project needs a new release
Expand Down
7 changes: 6 additions & 1 deletion import.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ function RecreateDb {
}

MessageInfo "Creating database $db_name..."
InvokeSqlQuery -query "USE master; CREATE DATABASE [$db_name] COLLATE SQL_Latin1_General_CP1_CS_AS;"
# `Latin1_General_100_CS_AS_SC_UTF8` collation with UTF-8 support requires MSSQL 2019 or later.
# Details: https://learn.microsoft.com/en-us/sql/relational-databases/collations/collation-and-unicode-support?view=sql-server-ver16#utf8
#
# Archived migration scripts may fail from script 0021 due to the migration of `text` to `varchar`.
# If you want to test scripts with the initial setup, use `SQL_Latin1_General_CP1_CI_AS` collation instead.
InvokeSqlQuery -query "USE master; CREATE DATABASE [$db_name] COLLATE Latin1_General_100_CS_AS_SC_UTF8;"
}

function RunInitialDbScripts {
Expand Down

0 comments on commit 1d61989

Please sign in to comment.