This repository has been archived by the owner on Dec 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Database Models & Schema
Sabbir Ahmed edited this page Dec 15, 2024
·
3 revisions
- Content Model
- Game Model
- User Model
- Wallet Model
- Transaction Model
- Item Model
- Inventory Model
- Server Model
- ServerUser Model
- GridCell Model
- Content Model
- Treasure Model
- TreasureFind Model
- Score Model
- Leaderboard Model
- LeaderboardEntry Model
- Associations Summary
- Notes and Next Steps
Table Name: contents
Column | Type | Constraints |
---|---|---|
id |
integer |
Primary key |
story_text |
text |
|
image_url |
string |
|
created_at |
datetime |
|
updated_at |
datetime |
has_many :grid_cells
Table Name: games
Column | Type | Constraints |
---|---|---|
id |
integer |
Primary key |
name |
string |
|
server_id |
integer |
null: false |
created_at |
datetime |
|
updated_at |
datetime |
belongs_to :server
has_many :messages
Table Name: users
Column | Type | Constraints |
---|---|---|
id |
integer |
Primary key |
username |
string |
null: false , unique: true
|
email |
string |
null: false , unique: true
|
encrypted_password |
string |
null: false (managed by Devise) |
reset_password_token |
string |
unique: true (managed by Devise) |
reset_password_sent_at |
datetime |
(managed by Devise) |
remember_created_at |
datetime |
(managed by Devise) |
created_at |
datetime |
|
updated_at |
datetime |
has_one :wallet, dependent: :destroy
has_many :server_users, dependent: :destroy
has_many :servers, through: :server_users
has_many :transactions, dependent: :destroy
has_many :inventories, dependent: :destroy
has_many :items, through: :inventories
has_many :scores, dependent: :destroy
has_many :treasure_finds, dependent: :destroy
has_many :leaderboard_entries, dependent: :destroy
has_many :leaderboards, through: :leaderboard_entries
Table Name: wallets
Column | Type | Constraints |
---|---|---|
id |
integer |
Primary key |
user_id |
integer |
null: false |
balance |
decimal |
precision: 10, scale: 2 |
created_at |
datetime |
|
updated_at |
datetime |
belongs_to :user
Table Name: transactions
Column | Type | Constraints |
---|---|---|
id |
integer |
Primary key |
user_id |
integer |
null: false |
transaction_type |
string |
|
amount |
decimal |
precision: 10, scale: 2 |
currency |
string |
|
payment_method |
string |
|
item_id |
integer |
|
quantity |
integer |
|
description |
text |
|
created_at |
datetime |
|
updated_at |
datetime |
belongs_to :user
-
belongs_to :item
, optional: true
Table Name: items
Column | Type | Constraints |
---|---|---|
id |
integer |
Primary key |
name |
string |
|
description |
text |
|
price |
decimal |
precision: 10, scale: 2 |
category |
string |
|
required_level |
integer |
|
created_at |
datetime |
|
updated_at |
datetime |
|
image_url |
string |
has_many :inventories
has_many :transactions
Table Name: inventories
Column | Type | Constraints |
---|---|---|
id |
integer |
Primary key |
user_id |
integer |
null: false |
item_id |
integer |
null: false |
quantity |
integer |
|
created_at |
datetime |
|
updated_at |
datetime |
|
item_name |
string |
|
server_user_id |
integer |
belongs_to :user
belongs_to :item
Table Name: servers
Column | Type | Constraints |
---|---|---|
id |
integer |
Primary key |
name |
string |
|
max_players |
integer |
|
created_by |
integer |
null: false |
created_at |
datetime |
|
updated_at |
datetime |
|
status |
string |
Default: 'pending' |
current_turn_server_user_id |
integer |
|
background_image_url |
string |
|
role |
string |
|
turn_count |
integer |
belongs_to :user, foreign_key: 'created_by'
has_many :server_users
has_many :games
has_many :leaderboards
has_many :scores
Table Name: server_users
Column | Type | Constraints |
---|---|---|
id |
integer |
Primary key |
user_id |
integer |
null: false |
server_id |
integer |
null: false |
current_position_x |
integer |
|
current_position_y |
integer |
|
created_at |
datetime |
|
updated_at |
datetime |
|
total_ap |
integer |
Default: 200 |
turn_ap |
integer |
Default: 2 |
shard_balance |
integer |
Default: 0 |
symbol |
string |
|
turn_order |
integer |
|
can_move_diagonally |
boolean |
|
diagonal_moves_left |
integer |
|
mirror_shield |
boolean |
|
turns_skipped |
integer |
|
cable_token |
string |
|
role |
integer |
null: false |
belongs_to :user
belongs_to :server
Table Name: grid_cells
Column | Type | Constraints |
---|---|---|
id |
integer |
Primary key |
server_id |
integer |
null: false |
x |
integer |
|
y |
integer |
|
content_id |
integer |
|
treasure_id |
integer |
|
created_at |
datetime |
|
updated_at |
datetime |
|
owner_id |
integer |
|
obstacle |
boolean |
Default: false |
fortified |
integer |
belongs_to :server
belongs_to :content
belongs_to :treasure
Table Name: contents
Column | Type | Constraints |
---|---|---|
id |
integer |
Primary key |
story_text |
text |
|
image_url |
string |
|
created_at |
datetime |
|
updated_at |
datetime |
has_many :grid_cells
Table Name: treasures
Column | Type | Constraints |
---|---|---|
id |
integer |
Primary key |
name |
string |
|
description |
text |
|
points |
integer |
|
item_id |
integer |
null: false |
unlock_criteria |
string |
|
created_at |
datetime |
|
updated_at |
datetime |
belongs_to :item
has_many :treasure_finds
Table Name: treasure_finds
Column | Type | Constraints |
---|---|---|
id |
integer |
Primary key |
user_id |
integer |
null: false |
treasure_id |
integer |
null: false |
server_id |
integer |
null: false |
found_at |
datetime |
|
created_at |
datetime |
|
updated_at |
datetime |
belongs_to :user
belongs_to :treasure
belongs_to :server
Table Name: scores
Column | Type | Constraints |
---|---|---|
id |
integer |
Primary key |
user_id |
integer |
null: false |
server_id |
integer |
null: false |
points |
integer |
|
level |
integer |
|
created_at |
datetime |
|
updated_at |
datetime |
belongs_to :user
belongs_to :server
Table Name: leaderboards
Column | Type | Constraints |
---|---|---|
id |
integer |
Primary key |
name |
string |
|
scope |
string |
|
server_id |
integer |
null: false |
created_at |
datetime |
|
updated_at |
datetime |
belongs_to :server
has_many :leaderboard_entries
Table Name: leaderboard_entries
Column | Type | Constraints |
---|---|---|
id |
integer |
Primary key |
leaderboard_id |
integer |
null: false |
user_id |
integer |
null: false |
points |
integer |
|
rank |
integer |
|
remaining_ap |
integer |
Default: 0 |
cells_occupied |
integer |
Default: 0 |
created_at |
datetime |
|
updated_at |
datetime |
belongs_to :leaderboard
belongs_to :user
-
User
: has one wallet, has many server_users, has many transactions, has many inventories, has many scores, has many treasure_finds, has many leaderboard_entries, has many leaderboards through leaderboard_entries. -
Server
: has many server_users, has many games, has many leaderboards, has many scores. -
ServerUser
: belongs to user and server. -
GridCell
: belongs to server, content, and treasure. -
Content
: has many grid_cells. -
Treasure
: belongs to item, has many treasure_finds. -
TreasureFind
: belongs to user, treasure, and server. -
Item
: has many inventories, has many transactions. -
Inventory
: belongs to user and item. -
Transaction
: belongs to user and item (optional). -
Leaderboard
: belongs to server, has many leaderboard_entries. -
LeaderboardEntry
: belongs to leaderboard and user.
- Review associations to ensure consistency across models.
- Implement necessary validations where applicable.
- Add any needed callbacks, scopes, or custom methods for business logic.
- Continue refining database queries and optimizing performance.