gamebox-dev / gamebox-api

API for managing a game collection
GNU Affero General Public License v3.0
0 stars 2 forks source link

Create Database and have the API connect to it. #8

Open FusTaFah opened 3 weeks ago

FusTaFah commented 3 weeks ago

Create a MSSQLS DB and hook it up to the backend.

Also ensure that the database structure looks somewhat like this:

Image

FusTaFah commented 6 days ago
use GameBox;

if not exists(select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'Game')
begin
    create table Game(
        id int identity(1,1) primary key constraint [PK_Game_ID_NotNull] not null,
        title varchar(100) constraint [DF_Game_Title_Null] null default null,
        description varchar(1000) constraint [DF_Game_Description_Null] null default null,
        imagePath varchar(200) constraint [DF_Game_ImagePath_Null] null default null,

    );
end

if not exists(select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'Platform')
begin
    create table Platform(
        id int constraint [PK_Platform_ID_NotNull] default 0,
        name varchar(10),
        primary key (id)
    );
end

if not exists(select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'GamePlatform')
begin
    create table GamePlatform(
        platformID int,
        gameID int,
        releaseDate date constraint [DF_GamePlatform_releaseDate_Null] null default null,
        foreign key (platformID) references [Platform](id),
        foreign key (gameID) references Game(id)
    );
end

if not exists(select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'User')
begin
    create table [User](
        id int identity(1,1) primary key constraint [PK_User_ID_NotNull] not null,

    );
end

if not exists(select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'CollectionEntry')
begin
    create table CollectionEntry(
        userID int,
        gameID int,
        platformID int,
        added datetime,
        foreign key (userID) references [User](id),
        foreign key (gameID) references Game(id),
        foreign key (platformID) references Platform(id)
    );
end
FusTaFah commented 6 days ago

There is now a database hosted by Azure. Need to add data to it and see if i can get a query to it using a connection string. Going to put the connection string into an environment variable using the new changes

FusTaFah commented 6 days ago

I have installed Entity Framework and got the database onto an Azure hosted SQL server. Going to probably be able to deploy the whole app to Azure too, I have free access for a year.