Skip to content

Commit 8f97d7e

Browse files
committed
Merge pull request #32 from ko4life-net/misc-changes
Misc changes to automate certain steps and docs
2 parents fdc0f81 + ebe9a33 commit 8f97d7e

File tree

5 files changed

+61
-33
lines changed

5 files changed

+61
-33
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 ko4life-net
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Knight Online Database
22

3-
This repository contains scripts to build the database from scratch.
3+
This repository contains scripts to build the database from scratch and set all the configurations needed for you to be able running the game.
44

55
Brief explanation of the directory structure under `src`:
66
- data - Insert queries based on the current db state
@@ -9,19 +9,32 @@ Brief explanation of the directory structure under `src`:
99
- procedure - Stored procedures based on the current db state
1010
- schema - Tables structure and constraints based on the current db state
1111

12+
1213
### Prerequisite
1314

14-
- Any MSSQL Express Server (confirmed to be working with 2008 and 2022)
15-
- Download the Express version from here: https://www.microsoft.com/en-us/sql-server/sql-server-downloads
16-
- Download the latest MSSQL Management Studio: https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms
17-
- 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
18-
- Powershell `sqlserver` module
19-
- Open Powershell as Admin and run the following command: `Install-Module sqlserver -AllowClobber -Force`
20-
- 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.
21-
- Python and installing via pip the following packages (if you get errors, run powershell as admin):
22-
- T-SQL code formatter: `pip install sqlfluff`
23-
- MSSQL scripter: `pip install mssql-scripter`
24-
- Note that if you're using [virtualenv](https://docs.python.org/3/library/venv.html) (recommended), you can simply install the requirements.txt.
15+
- 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`
16+
- Microsoft SQL Server Express or Developer (confirmed to be working with versions 2022 and 2008)
17+
- [SQL Server](https://www.microsoft.com/en-us/sql-server/sql-server-downloads)
18+
- [SQL Management Studio](https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms)
19+
- [Git](https://git-scm.com/download/win) (version 2.45.1 at the time of writing)
20+
- [Python](https://www.python.org/downloads/) (version 3.12.3 at the time of writing)
21+
- During installation in the `Advanced Options` make sure to tick `Add Python to environment variables`
22+
- Once finished, install the required packages with the following command: `pip install -r requirements.txt`
23+
24+
25+
### Getting Started
26+
27+
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:
28+
```powershell
29+
(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances
30+
```
31+
32+
Assuming you set a custom name to your SQL Server instance, you may invoke the import command as follows:
33+
```powershell
34+
.\import.ps1 -server_name ".\MyCustomInstanceName"
35+
```
36+
37+
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.
2538

2639

2740
### Development
@@ -45,17 +58,3 @@ Release process should follow for every release we create in the [main ko projec
4558

4659
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.
4760
Maybe in the future this will change if it makes things difficult and we maintain a separate development branch.
48-
49-
### How to use
50-
51-
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:
52-
```powershell
53-
(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances
54-
```
55-
56-
Assuming you set a custom name to your SQL Server instance, you may invoke the import command as follows:
57-
```powershell
58-
.\import.ps1 -server_name ".\MyCustomInstanceName"
59-
```
60-
61-
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.

import.ps1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,13 @@ function CreateDbCredentials {
149149
}
150150

151151
function Main {
152-
# Check if the sqlserver module is installed
153-
if (-not (Get-Module -Name sqlserver -ListAvailable)) {
154-
MessageError "Error: The 'sqlserver' powershell module is not installed."
155-
MessageError "Please open PowerShell as Administrator and execute the following command to install it:"
156-
MessageError "Install-Module sqlserver -AllowClobber -Force"
157-
exit_script 1 $quiet
152+
if (-not (Get-Module sqlserver -ListAvailable)) {
153+
MessageInfo "Installing missing 'sqlserver' powershell module..."
154+
# ensure we first install the NuGet package provider so that Install-Module won't prompt us
155+
if (-not (Get-PackageProvider -ListAvailable | Where-Object { $_.Name -eq 'NuGet' })) {
156+
Install-PackageProvider NuGet -Force -Scope CurrentUser
157+
}
158+
Install-Module sqlserver -AllowClobber -Force -Scope CurrentUser
158159
}
159160

160161
ValidateArgs

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
virtualenv
12
sqlfluff==2.3.5
23
mssql-scripter==1.0.0a23

utils.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ function exit_script {
1919
function ValidateServerNameInput {
2020
param ([string][Parameter(Mandatory, Position = 0)] $server_name)
2121

22-
$sql_instances = @((Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances)
22+
$mssql_reg = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server' -ErrorAction Ignore
23+
if (-not $mssql_reg) {
24+
MessageError "Error: MSSQL Server is not installed. Please follow the prerequisite section in the readme file."
25+
return $false
26+
}
27+
28+
$sql_instances = @($mssql_reg.InstalledInstances)
2329
if ($server_name -in "localhost", ".") {
2430
$server_instance_name = "MSSQLSERVER"
2531
} else {

0 commit comments

Comments
 (0)