Added basic setup program to get initial data into database
This commit is contained in:
parent
13f92d49cc
commit
63b95b7ee6
3
.gitignore
vendored
3
.gitignore
vendored
@ -3,3 +3,6 @@
|
|||||||
/API/bin/
|
/API/bin/
|
||||||
/API/obj/
|
/API/obj/
|
||||||
/API/appsettings.*
|
/API/appsettings.*
|
||||||
|
/Setup/bin/
|
||||||
|
/Setup/obj/
|
||||||
|
/Setup/appsettings.*
|
||||||
|
7
.idea/.idea.sanAntonioSeniorGolf/.idea/sqldialects.xml
generated
Normal file
7
.idea/.idea.sanAntonioSeniorGolf/.idea/sqldialects.xml
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="SqlDialectMappings">
|
||||||
|
<file url="file://$PROJECT_DIR$/Setup/Filler/Grants.sql" dialect="MySQL" />
|
||||||
|
<file url="file://$PROJECT_DIR$/Setup/Filler/Permissions.sql" dialect="MySQL" />
|
||||||
|
</component>
|
||||||
|
</project>
|
180
Setup/Filler/Grants.sql
Normal file
180
Setup/Filler/Grants.sql
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
SET FOREIGN_KEY_CHECKS = 0;
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.color.get.all', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.color.get.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.color.get', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.color.add', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.color.update.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.color.update', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.color.delete.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.color.delete', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.event.get.all', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.event.get.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.event.get', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.event.add', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.event.update.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.event.update', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.event.delete.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.event.delete', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.grant.get.all', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.grant.get.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.grant.get', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.grant.add', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.grant.update.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.grant.update', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.grant.delete.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.grant.delete', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.image.get.all', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.image.get.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.image.get', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.image.add', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.image.update.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.image.update', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.image.delete.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.image.delete', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.permission.get.all', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.permission.get.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.permission.get', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.permission.add', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.permission.update.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.permission.update', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.permission.delete.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.permission.delete', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.savedEvent.get.all', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.savedEvent.get.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.savedEvent.get', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.savedEvent.add', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.savedEvent.update.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.savedEvent.update', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.savedEvent.delete.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.savedEvent.delete', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.user.get.all', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.user.get.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.user.get', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.user.add', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.user.update.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.user.update', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.user.update.self', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.user.update.names', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.user.update.phoneNumber', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.user.update.permission', 1, NOW(), 1);
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||||
|
VALUES ('api.user.delete.any', 1, NOW(), 1);
|
||||||
|
|
||||||
|
SET FOREIGN_KEY_CHECKS = 1;
|
6
Setup/Filler/Permissions.sql
Normal file
6
Setup/Filler/Permissions.sql
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
SET FOREIGN_KEY_CHECKS = 0;
|
||||||
|
|
||||||
|
INSERT INTO san_antonio_senior_golf.permissions (name, updated, updater)
|
||||||
|
VALUES ('admin', NOW(), 1);
|
||||||
|
|
||||||
|
SET FOREIGN_KEY_CHECKS = 1;
|
116
Setup/Program.cs
Normal file
116
Setup/Program.cs
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
using API.Hashing;
|
||||||
|
using API.Hashing.Interfaces;
|
||||||
|
using DAL.Contexts;
|
||||||
|
using DAL.Models;
|
||||||
|
using DAL.Values;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using MySql.Data.MySqlClient;
|
||||||
|
using Mysqlx.Session;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Data.Common;
|
||||||
|
|
||||||
|
namespace Setup
|
||||||
|
{
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
public static bool lineIsYes(string? input)
|
||||||
|
{
|
||||||
|
if (input == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
input = input.Trim().ToLower();
|
||||||
|
switch (input)
|
||||||
|
{
|
||||||
|
case "y":
|
||||||
|
case "yes":
|
||||||
|
return true;
|
||||||
|
case "n":
|
||||||
|
case "no":
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string getStringWithConfirmation(string message)
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
Console.Write(message);
|
||||||
|
string? input = Console.ReadLine();
|
||||||
|
Console.WriteLine();
|
||||||
|
if (input == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Console.Write($"Is '{input}' correct? [Y/N]: ");
|
||||||
|
if (lineIsYes(Console.ReadLine()))
|
||||||
|
{
|
||||||
|
Console.WriteLine();
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.Write("Entering setup. Only run this once. Will reinstate database. Continue? [Y/N]: ");
|
||||||
|
if (!lineIsYes(Console.ReadLine()))
|
||||||
|
System.Environment.Exit(0);
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
|
string connectionString = getStringWithConfirmation("Enter connection string: ");
|
||||||
|
|
||||||
|
DbContextOptionsBuilder<SASGContext> optionsBuilder = new DbContextOptionsBuilder<SASGContext>();
|
||||||
|
optionsBuilder.UseMySQL(connectionString);
|
||||||
|
|
||||||
|
SASGContext context = new SASGContext(optionsBuilder.Options);
|
||||||
|
|
||||||
|
string firstName = getStringWithConfirmation("Enter admin first name: ");
|
||||||
|
string lastname = getStringWithConfirmation("Enter admin last name: ");
|
||||||
|
PhoneNumber phoneNumber = getStringWithConfirmation("Enter admin phone number: ");
|
||||||
|
string unHashedPassword = getStringWithConfirmation("Enter admin password: ");
|
||||||
|
|
||||||
|
HashingType defaultHashingType = Enum.Parse<HashingType>(
|
||||||
|
getStringWithConfirmation($"Enter default hashing type [{String.Join(", ", Enum.GetNames(typeof(HashingType)))}]: "));
|
||||||
|
|
||||||
|
IHashingFactory hashingFactory = new HashingFactory();
|
||||||
|
IHashingAlgorithm algorithm = hashingFactory.getAlgorithm(defaultHashingType) ?? throw new InvalidOperationException();
|
||||||
|
|
||||||
|
byte[] salt;
|
||||||
|
string password = algorithm.hash(unHashedPassword, out salt);
|
||||||
|
|
||||||
|
Console.Write("About to touch db. Continue? [Y/N]: ");
|
||||||
|
if (!lineIsYes(Console.ReadLine()))
|
||||||
|
System.Environment.Exit(0);
|
||||||
|
|
||||||
|
MySqlConnection conn = (MySqlConnection) context.Database.GetDbConnection();
|
||||||
|
|
||||||
|
conn.Open();
|
||||||
|
using (MySqlCommand reader = new MySqlCommand(File.ReadAllText("Filler/Permissions.sql"), conn))
|
||||||
|
{
|
||||||
|
reader.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
using (MySqlCommand reader = new MySqlCommand(File.ReadAllText("Filler/Grants.sql"), conn))
|
||||||
|
{
|
||||||
|
reader.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
conn.Close();
|
||||||
|
|
||||||
|
context.users.Add(new User
|
||||||
|
{
|
||||||
|
firstName = firstName,
|
||||||
|
lastName = lastname,
|
||||||
|
phoneNumber = phoneNumber,
|
||||||
|
password = password,
|
||||||
|
salt = salt,
|
||||||
|
hashingType = defaultHashingType,
|
||||||
|
permissionId = 1,
|
||||||
|
});
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
26
Setup/Setup.csproj
Normal file
26
Setup/Setup.csproj
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="../DAL/DAL.csproj"/>
|
||||||
|
<ProjectReference Include="../API/API.csproj"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="Filler\Grants.sql" />
|
||||||
|
<Content Include="Filler\Grants.sql">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
<None Remove="Filler\Permissions.sql" />
|
||||||
|
<Content Include="Filler\Permissions.sql">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DAL", "DAL\DAL.csproj", "{E
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{829DACCE-0D9E-43C8-A8C1-692C9FF6804A}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{829DACCE-0D9E-43C8-A8C1-692C9FF6804A}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Setup", "Setup\Setup.csproj", "{B887051E-90C7-43BA-A08B-3958D570DCA7}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -18,5 +20,9 @@ Global
|
|||||||
{829DACCE-0D9E-43C8-A8C1-692C9FF6804A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{829DACCE-0D9E-43C8-A8C1-692C9FF6804A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{829DACCE-0D9E-43C8-A8C1-692C9FF6804A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{829DACCE-0D9E-43C8-A8C1-692C9FF6804A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{829DACCE-0D9E-43C8-A8C1-692C9FF6804A}.Release|Any CPU.Build.0 = Release|Any CPU
|
{829DACCE-0D9E-43C8-A8C1-692C9FF6804A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B887051E-90C7-43BA-A08B-3958D570DCA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B887051E-90C7-43BA-A08B-3958D570DCA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B887051E-90C7-43BA-A08B-3958D570DCA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B887051E-90C7-43BA-A08B-3958D570DCA7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
Loading…
x
Reference in New Issue
Block a user