From fd37a6fa6256942d3257dc953484f4b3781097fa Mon Sep 17 00:00:00 2001 From: Steve Williams <90905675+stevewgr@users.noreply.github.com> Date: Wed, 5 Jun 2024 23:44:05 -0400 Subject: [PATCH 1/5] Fix ValidateServerNameInput to first check if SQL Server is installed. --- utils.ps1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/utils.ps1 b/utils.ps1 index 95dff6c..6b58902 100644 --- a/utils.ps1 +++ b/utils.ps1 @@ -19,7 +19,13 @@ function exit_script { function ValidateServerNameInput { param ([string][Parameter(Mandatory, Position = 0)] $server_name) - $sql_instances = @((Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances) + $mssql_reg = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server' -ErrorAction Ignore + if (-not $mssql_reg) { + MessageError "Error: MSSQL Server is not installed. Please follow the prerequisite section in the readme file." + return $false + } + + $sql_instances = @($mssql_reg.InstalledInstances) if ($server_name -in "localhost", ".") { $server_instance_name = "MSSQLSERVER" } else { From 0a3ff687e8dab5e5c62b8f14e05ccc260a91f26e Mon Sep 17 00:00:00 2001 From: Steve Williams <90905675+stevewgr@users.noreply.github.com> Date: Wed, 5 Jun 2024 23:49:10 -0400 Subject: [PATCH 2/5] Install automatically powershell sqlserver module. Note that users often struggle with this step, since it either fails to them due to missing admin rights or not following steps properly. Therefore and to ease the initial process, we can install these modules without admin permissions if we install it to the current user scope. That way in the initial run it will install them automatically so we can reduce the steps from the readme. --- import.ps1 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/import.ps1 b/import.ps1 index 5985a0f..b6964a5 100644 --- a/import.ps1 +++ b/import.ps1 @@ -149,12 +149,13 @@ function CreateDbCredentials { } function Main { - # Check if the sqlserver module is installed - if (-not (Get-Module -Name sqlserver -ListAvailable)) { - MessageError "Error: The 'sqlserver' powershell module is not installed." - MessageError "Please open PowerShell as Administrator and execute the following command to install it:" - MessageError "Install-Module sqlserver -AllowClobber -Force" - exit_script 1 $quiet + if (-not (Get-Module sqlserver -ListAvailable)) { + MessageInfo "Installing missing 'sqlserver' powershell module..." + # ensure we first install the NuGet package provider so that Install-Module won't prompt us + if (-not (Get-PackageProvider -ListAvailable | Where-Object { $_.Name -eq 'NuGet' })) { + Install-PackageProvider NuGet -Force -Scope CurrentUser + } + Install-Module sqlserver -AllowClobber -Force -Scope CurrentUser } ValidateArgs From fdabc7e916f19c507dd70811f21b898548a46131 Mon Sep 17 00:00:00 2001 From: Steve Williams <90905675+stevewgr@users.noreply.github.com> Date: Wed, 5 Jun 2024 23:51:26 -0400 Subject: [PATCH 3/5] Add virtualenv to requirements.txt. --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 650576b..f54bfa3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ +virtualenv sqlfluff==2.3.5 mssql-scripter==1.0.0a23 From 6f5bde6d9e19e3b289ca4e6c6dda93109e2f95c8 Mon Sep 17 00:00:00 2001 From: Steve Williams <90905675+stevewgr@users.noreply.github.com> Date: Wed, 5 Jun 2024 23:56:46 -0400 Subject: [PATCH 4/5] Update readme to reflect the new changes. --- README.md | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 4d61541..efc15f5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Knight Online Database -This repository contains scripts to build the database from scratch. +This repository contains scripts to build the database from scratch and set all the configurations needed for you to be able running the game. Brief explanation of the directory structure under `src`: - data - Insert queries based on the current db state @@ -9,19 +9,32 @@ Brief explanation of the directory structure under `src`: - procedure - Stored procedures based on the current db state - schema - Tables structure and constraints based on the current db state + ### Prerequisite -- Any MSSQL Express Server (confirmed to be working with 2008 and 2022) - - Download the Express version from here: https://www.microsoft.com/en-us/sql-server/sql-server-downloads - - Download the latest MSSQL Management Studio: https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms - - Note that it can connect to any version of SQL Server, so even if you use 2008, just get the latest Management Studio for better development experience -- Powershell `sqlserver` module - - Open Powershell as Admin and run the following command: `Install-Module sqlserver -AllowClobber -Force` - - Note that if you're getting errors during the installation, it is likely because because your SQL installation installed its own powershell module which conflicts with the one we intend to use. They're incompatible and behave differently when creating db exports, hence you may want to delete it from your System Environment Variable `PSModulePath` and restart powershell to reload without these modules. Basically if you see in your `PSModulePath` environment variable something with `Microsoft SQL Server`, just remove it, since we want to use the module that we intend to use. -- Python and installing via pip the following packages (if you get errors, run powershell as admin): - - T-SQL code formatter: `pip install sqlfluff` - - MSSQL scripter: `pip install mssql-scripter` - - Note that if you're using [virtualenv](https://docs.python.org/3/library/venv.html) (recommended), you can simply install the requirements.txt. +- 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) + - [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) +- [Python](https://www.python.org/downloads/) (version 3.12.3 at the time of writing) + - During installation in the `Advanced Options` make sure to tick `Add Python to environment variables` + - Once finished, install the required packages with the following command: `pip install -r requirements.txt` + + +### Getting Started + +Before running the `import.ps1` script, check that the `$server_name` variable matches with your current server name. If you installed SQL Server using the default instance, then the default arguments should be working fine, otherwise you can provide the script an argument with your custom server name. You can run the following command in powershell to know the names of your current SQL Servers: +```powershell +(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances +``` + +Assuming you set a custom name to your SQL Server instance, you may invoke the import command as follows: +```powershell +.\import.ps1 -server_name ".\MyCustomInstanceName" +``` + +Once the import script finished importing the db, it will also invoke the `odbcad.ps1` script automatically for you to set odbc configurations so that the server files can connect with your db. ### Development @@ -45,17 +58,3 @@ Release process should follow for every release we create in the [main ko projec In other words, we use the `master` branch as the development and release branch, but when tagging, they are all fixed to a specific tag. Maybe in the future this will change if it makes things difficult and we maintain a separate development branch. - -### How to use - -Before running the `import.ps1` script, check that the `$server_name` variable matches with your current server name. If you installed SQL Server using the default instance, then the defaults arguments should work, otherwise you can provide to the script an argument with your custom server name. You can run the following command in powershell to know the names of your current SQL Servers: -```powershell -(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances -``` - -Assuming you set a custom name to your SQL Server instance, you may invoke the import command as follows: -```powershell -.\import.ps1 -server_name ".\MyCustomInstanceName" -``` - -Once the import script finished importing the db, it will also invoke the `odbcad.ps1` script for you to automatically set odbc configurations so that the server files can connect with your db. From ebe9a33a9c0768c03b5e898f0b1aca82da772149 Mon Sep 17 00:00:00 2001 From: Steve Williams <90905675+stevewgr@users.noreply.github.com> Date: Wed, 5 Jun 2024 23:57:04 -0400 Subject: [PATCH 5/5] Add LICENSE file. --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2e7e4a0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 ko4life-net + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.