-
Notifications
You must be signed in to change notification settings - Fork 0
The Database
Donapieppo edited this page Jun 9, 2016
·
3 revisions
Two words about the database:
Departments/Organizations/Bunkers, you name it. In my University are just organizational units each with its own money to buy toners.
Just a list of vendors (HP, Kyocera...)
Common to all organizations are printer_models:
+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| vendor_id | int(11) | NO | MUL | NULL | |
| name | varchar(255) | YES | | NULL | |
| laser | tinyint(1) | YES | | NULL | |and toner_models:
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| vendor_id | int(11) | NO | MUL | NULL | |
| name | varchar(255) | YES | | NULL | |
| compatible | tinyint(1) | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+is done with the table printer_models_toner_models
+------------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+---------+------+-----+---------+-------+
| printer_model_id | int(11) | NO | MUL | NULL | |
| toner_model_id | int(11) | NO | MUL | NULL | |
+------------------+---------+------+-----+---------+-------+in order to have
class TonerModel < ActiveRecord::Base
belongs_to :vendor
has_and_belongs_to_many :printer_modelsand
class PrinterModel < ActiveRecord::Base
belongs_to :vendor
has_and_belongs_to_many :toner_modelsnote: vendor in PrinterModel or TonerModel do not have to be the same. Xerox for example makes toners for HP (compatible).
Every organization has a list of printers and toners.
Printers
+------------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+------------------+------+-----+---------+----------------+
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
| organization_id | int(11) unsigned | YES | MUL | NULL | |
| printer_model_id | int(11) unsigned | YES | MUL | NULL | |
| name | varchar(255) | YES | | NULL | |
| description | text | YES | | NULL | |
| rent | tinyint(1) | YES | | NULL | |
+------------------+------------------+------+-----+---------+----------------+Toners
+-----------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+------------------+------+-----+---------+----------------+
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
| organization_id | int(11) unsigned | YES | MUL | NULL | |
| toner_model_id | int(11) unsigned | YES | MUL | NULL | |
| number | int(11) unsigned | YES | | 0 | |
| gift | tinyint(1) | YES | | NULL | |
+-----------------+------------------+------+-----+---------+----------------+The toners can be marked as obsolete for the organization (usually the printer is broken or dismissed) by setting true to gift column.
This kind of toners are shown to organizations with compatible printers can be asked.