|
CREATE TABLE IF NOT EXISTS `bill` ( |
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
`name` varchar(20) NOT NULL, |
|
PRIMARY KEY (`id`) |
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; |
|
|
|
-- -------------------------------------------------------- |
|
|
|
-- |
|
-- Table structure for table `members` |
|
-- |
|
|
|
CREATE TABLE IF NOT EXISTS `members` ( |
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
`user_id` int(10) unsigned NOT NULL, |
|
`bill_id` int(10) unsigned NOT NULL, |
|
PRIMARY KEY (`id`), |
|
KEY `user_id` (`user_id`), |
|
KEY `bill_id` (`bill_id`) |
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; |
|
|
|
-- -------------------------------------------------------- |
|
|
|
-- |
|
-- Table structure for table `revision` |
|
-- |
|
|
|
CREATE TABLE IF NOT EXISTS `revision` ( |
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
`author_id` int(10) unsigned NOT NULL, |
|
`bill_id` int(10) unsigned NOT NULL, |
|
`text` text NOT NULL, |
|
PRIMARY KEY (`id`), |
|
KEY `author_id` (`author_id`), |
|
KEY `bill_id` (`bill_id`) |
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; |
|
|
|
-- -------------------------------------------------------- |
|
|
|
-- |
|
-- Table structure for table `user` |
|
-- |
|
|
|
CREATE TABLE IF NOT EXISTS `user` ( |
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
`name` varchar(20) NOT NULL, |
|
PRIMARY KEY (`id`) |
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; |
|
|
|
-- -------------------------------------------------------- |
|
|
|
-- |
|
-- Table structure for table `vote` |
|
-- |
|
|
|
CREATE TABLE IF NOT EXISTS `vote` ( |
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
`user_id` int(10) unsigned NOT NULL, |
|
`revision_id` int(10) unsigned NOT NULL, |
|
`vote` int(10) unsigned NOT NULL, |
|
PRIMARY KEY (`id`), |
|
KEY `user_id` (`user_id`), |
|
KEY `revision_id` (`revision_id`), |
|
KEY `vote` (`vote`) |
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; |
|
|
|
-- |
|
-- Constraints for dumped tables |
|
-- |
|
|
|
-- |
|
-- Constraints for table `members` |
|
-- |
|
ALTER TABLE `members` |
|
ADD CONSTRAINT `members_ibfk_2` FOREIGN KEY (`bill_id`) REFERENCES `bill` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, |
|
ADD CONSTRAINT `members_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; |
|
|
|
-- |
|
-- Constraints for table `revision` |
|
-- |
|
ALTER TABLE `revision` |
|
ADD CONSTRAINT `revision_ibfk_2` FOREIGN KEY (`bill_id`) REFERENCES `bill` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, |
|
ADD CONSTRAINT `revision_ibfk_1` FOREIGN KEY (`author_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; |
|
|
|
-- |
|
-- Constraints for table `vote` |
|
-- |
|
ALTER TABLE `vote` |
|
ADD CONSTRAINT `vote_ibfk_2` FOREIGN KEY (`revision_id`) REFERENCES `revision` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, |
|
ADD CONSTRAINT `vote_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; |
I'm not sure what NoSQL auto schema discovery is (even after googling it). However, this is the idea that you deal with objects passing back-and-forth between the user agent and the server. Since MySQL has a copy of the foreign keys between tables (object collections), why write PHP controllers or validation handlers at all when you can just pass a couple objects to PHP and have it figure out the access restrictions, object types, relations, and everything else.
So, say I login. I now have my user object id. Each time I make a request I pass it along with the type of object I want to create/update/delete (like a vote) back to the server. Now the server has two objects (my user) and vote - it can trace back through the relations in the schema to find out if there is a matching user object to mine that has permission create/update/delete the vote object I just passed. I now have a PHP script that builds the CRUD services I need without writing controller code for each and ever type of object I want to create (forum post, blog article, user, membership, ticket, etc...)
Perhaps add a config file with validation closures for each column type and your done.