Skip to content

Commit

Permalink
Merge pull request #32 from ko4life-net/misc-changes
Browse files Browse the repository at this point in the history
Misc changes to automate certain steps and docs
  • Loading branch information
stevewgr committed Jun 6, 2024
2 parents fdc0f81 + ebe9a33 commit 8f97d7e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 33 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
51 changes: 25 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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.
13 changes: 7 additions & 6 deletions import.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
virtualenv
sqlfluff==2.3.5
mssql-scripter==1.0.0a23
8 changes: 7 additions & 1 deletion utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8f97d7e

Please sign in to comment.