I'm doing a project to manage membership and other kind of payments, but mainly membership so I created a polymorphic schema. any idea, improvement, for some reason I don't fully convinced about the schema.
as you will see, the idea of having month, year NULL-ABLE is allow save record of any other payment
CREATE TABLE IF NOT EXISTS `orders` (
`id` int(11) NOT NULL auto_increment,
`partner_id` int(11) NOT NULL,
`status` enum('pending','accepted','cancelled','other') NOT NULL,
`created_on` datetime NOT NULL,
`concept` varchar(250) NOT NULL,
`type` enum('membership','other') NOT NULL default 'membership',
`source` enum('dineromail','casati','deposit','other') NOT NULL default 'dineromail',
`notes` text NULL,
`last_check_on` datetime default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM ;
CREATE TABLE IF NOT EXISTS `payments` (
`id` int(11) NOT NULL auto_increment,
`order_id` int(11) NOT NULL,
`month` int(11) default NULL,
`year` int(11) default NULL,
`amount` float NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `idx-order_id-month-year` (`order_id`,`month`,`year`)
) ENGINE=MyISAM ;
CREATE TABLE IF NOT EXISTS `partners` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(255) default NULL,
`last_name` varchar(255) default NULL,
) ENGINE=MyISAM;