bcirpggithubmirror/Phase2/Godot_Toolset/Documentation/GenreDatabaseSchemas.md

72 lines
2.3 KiB
Markdown
Raw Normal View History

1. **Table: Items**
- This table will store information about base items like powerups.
```sql
CREATE TABLE items (
item_id serial PRIMARY KEY,
name VARCHAR(255) NOT NULL
);
```
2. **Table: Synonyms**
- This table will store synonyms for each item, referencing the `items` table.
```sql
CREATE TABLE synonyms (
synonym_id serial PRIMARY KEY,
item_id INT REFERENCES items(item_id),
synonym VARCHAR(255) NOT NULL
);
```
3. **Table: Genres**
- This table will store different genres, like "fantasy" or "modern day."
```sql
CREATE TABLE genres (
genre_id serial PRIMARY KEY,
name VARCHAR(255) NOT NULL
);
```
4. **Table: Items_Genres**
- This table will establish a many-to-many relationship between items and genres, as an item can belong to multiple genres.
```sql
CREATE TABLE items_genres (
item_id INT REFERENCES items(item_id),
genre_id INT REFERENCES genres(genre_id),
PRIMARY KEY (item_id, genre_id)
);
```
With this schema, you can:
- Add base items like powerups to the `items` table.
- Associate synonyms for each base item in the `synonyms` table, referencing the corresponding item.
- Categorize base items into different genres in the `genres` table.
- Establish relationships between base items and genres in the `items_genres` table.
Here's an example of how you might use this schema:
```sql
-- Insert a base item
INSERT INTO items (name) VALUES ('Health Potion');
-- Insert synonyms for the base item
INSERT INTO synonyms (item_id, synonym) VALUES (1, 'Health Potion');
INSERT INTO synonyms (item_id, synonym) VALUES (1, 'Stimpack');
-- Insert genres
INSERT INTO genres (name) VALUES ('Fantasy');
INSERT INTO genres (name) VALUES ('Modern Day');
-- Associate the base item with genres
INSERT INTO items_genres (item_id, genre_id) VALUES (1, 1); -- Health Potion belongs to Fantasy
INSERT INTO items_genres (item_id, genre_id) VALUES (1, 2); -- Health Potion also belongs to Modern Day
-- Select the Fantasy name of an the heavy armor base item that you are looking for.
SELECT genres.name
FROM genres
JOIN items_genres ON genres.genre_id = items_genres.genre_id
JOIN base_items ON items_genres.base_item_id = base_items.item_id
WHERE base_items.name = 'heavy armor'
AND genres.name = 'Fantasy';
```