Skip to content

Commit

Permalink
Added schema files for mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
ameerkat committed Aug 21, 2011
1 parent 5f6c6ff commit f03475b
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 7 deletions.
Binary file modified db_schema.mwb
Binary file not shown.
Binary file modified db_schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
150 changes: 150 additions & 0 deletions schemas/mysql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";

--
-- Database: `imdb`
--

-- --------------------------------------------------------

--
-- Table structure for table `acted_in`
--

CREATE TABLE IF NOT EXISTS `acted_in` (
`idacted_in` int(11) NOT NULL AUTO_INCREMENT,
`idmovies` int(11) NOT NULL,
`idseries` int(11) DEFAULT NULL,
`idactors` int(11) NOT NULL,
`character` varchar(255) NOT NULL,
`billing_position` int(11) DEFAULT NULL,
PRIMARY KEY (`idacted_in`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `actors`
--

CREATE TABLE IF NOT EXISTS `actors` (
`idactors` int(11) NOT NULL AUTO_INCREMENT,
`lname` varchar(255) NOT NULL,
`fname` varchar(255) NOT NULL,
`mname` varchar(255) DEFAULT NULL,
`gender` int(11) NOT NULL,
`number` int(11) DEFAULT NULL,
PRIMARY KEY (`idactors`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `aka_names`
--

CREATE TABLE IF NOT EXISTS `aka_names` (
`idaka_names` int(11) NOT NULL AUTO_INCREMENT,
`idactors` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`idaka_names`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `aka_titles`
--

CREATE TABLE IF NOT EXISTS `aka_titles` (
`idaka_titles` int(11) NOT NULL AUTO_INCREMENT,
`idmovies` int(11) NOT NULL,
`title` varchar(255) NOT NULL,
`location` varchar(63) DEFAULT NULL,
`year` year(4) DEFAULT NULL,
PRIMARY KEY (`idaka_titles`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `genres`
--

CREATE TABLE IF NOT EXISTS `genres` (
`idgenres` int(11) NOT NULL AUTO_INCREMENT,
`genre` varchar(63) NOT NULL,
PRIMARY KEY (`idgenres`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `keywords`
--

CREATE TABLE IF NOT EXISTS `keywords` (
`idkeywords` int(11) NOT NULL AUTO_INCREMENT,
`keyword` varchar(127) NOT NULL,
PRIMARY KEY (`idkeywords`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `movies`
--

CREATE TABLE IF NOT EXISTS `movies` (
`idmovies` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`year` year(4) NOT NULL,
`number` int(11) DEFAULT NULL,
`type` int(11) DEFAULT NULL,
`location` varchar(63) DEFAULT NULL,
`language` varchar(63) DEFAULT NULL,
PRIMARY KEY (`idmovies`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `movies_genres`
--

CREATE TABLE IF NOT EXISTS `movies_genres` (
`idmovies_genres` int(11) NOT NULL AUTO_INCREMENT,
`idmovies` int(11) NOT NULL,
`idgenres` int(11) NOT NULL,
`idseries` int(11) DEFAULT NULL,
PRIMARY KEY (`idmovies_genres`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `movies_keywords`
--

CREATE TABLE IF NOT EXISTS `movies_keywords` (
`idmovies_keywords` int(11) NOT NULL AUTO_INCREMENT,
`idmovies` int(11) NOT NULL,
`idkeywords` int(11) NOT NULL,
`idseries` int(11) DEFAULT NULL,
PRIMARY KEY (`idmovies_keywords`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `series`
--

CREATE TABLE IF NOT EXISTS `series` (
`idseries` int(11) NOT NULL AUTO_INCREMENT,
`idmovies` int(11) NOT NULL,
`name` varchar(255) DEFAULT NULL,
`season` int(11) DEFAULT NULL,
`number` int(11) DEFAULT NULL,
PRIMARY KEY (`idseries`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
150 changes: 150 additions & 0 deletions schemas/mysql.use_dict.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";

--
-- Database: `imdb`
--

-- --------------------------------------------------------

--
-- Table structure for table `acted_in`
--

CREATE TABLE IF NOT EXISTS `acted_in` (
`idacted_in` int(11) NOT NULL AUTO_INCREMENT,
`idmovies` int(11) NOT NULL,
`idseries` int(11) DEFAULT NULL,
`idactors` int(11) NOT NULL,
`character` varchar(255) NOT NULL,
`billing_position` int(11) DEFAULT NULL,
PRIMARY KEY (`idacted_in`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `actors`
--

CREATE TABLE IF NOT EXISTS `actors` (
`idactors` int(11) NOT NULL,
`lname` varchar(255) NOT NULL,
`fname` varchar(255) NOT NULL,
`mname` varchar(255) DEFAULT NULL,
`gender` int(11) NOT NULL,
`number` int(11) DEFAULT NULL,
PRIMARY KEY (`idactors`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `aka_names`
--

CREATE TABLE IF NOT EXISTS `aka_names` (
`idaka_names` int(11) NOT NULL AUTO_INCREMENT,
`idactors` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`idaka_names`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `aka_titles`
--

CREATE TABLE IF NOT EXISTS `aka_titles` (
`idaka_titles` int(11) NOT NULL AUTO_INCREMENT,
`idmovies` int(11) NOT NULL,
`title` varchar(255) NOT NULL,
`location` varchar(63) DEFAULT NULL,
`year` year(4) DEFAULT NULL,
PRIMARY KEY (`idaka_titles`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `genres`
--

CREATE TABLE IF NOT EXISTS `genres` (
`idgenres` int(11) NOT NULL,
`genre` varchar(63) NOT NULL,
PRIMARY KEY (`idgenres`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `keywords`
--

CREATE TABLE IF NOT EXISTS `keywords` (
`idkeywords` int(11) NOT NULL,
`keyword` varchar(127) NOT NULL,
PRIMARY KEY (`idkeywords`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `movies`
--

CREATE TABLE IF NOT EXISTS `movies` (
`idmovies` int(11) NOT NULL,
`title` varchar(255) NOT NULL,
`year` year(4) NOT NULL,
`number` int(11) DEFAULT NULL,
`type` int(11) DEFAULT NULL,
`location` varchar(63) DEFAULT NULL,
`language` varchar(63) DEFAULT NULL,
PRIMARY KEY (`idmovies`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `movies_genres`
--

CREATE TABLE IF NOT EXISTS `movies_genres` (
`idmovies_genres` int(11) NOT NULL AUTO_INCREMENT,
`idmovies` int(11) NOT NULL,
`idgenres` int(11) NOT NULL,
`idseries` int(11) DEFAULT NULL,
PRIMARY KEY (`idmovies_genres`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `movies_keywords`
--

CREATE TABLE IF NOT EXISTS `movies_keywords` (
`idmovies_keywords` int(11) NOT NULL AUTO_INCREMENT,
`idmovies` int(11) NOT NULL,
`idkeywords` int(11) NOT NULL,
`idseries` int(11) DEFAULT NULL,
PRIMARY KEY (`idmovies_keywords`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `series`
--

CREATE TABLE IF NOT EXISTS `series` (
`idseries` int(11) NOT NULL,
`idmovies` int(11) NOT NULL,
`name` varchar(255) DEFAULT NULL,
`season` int(11) DEFAULT NULL,
`number` int(11) DEFAULT NULL,
PRIMARY KEY (`idseries`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
1 change: 1 addition & 0 deletions schemas/sqlite.schema → schemas/sqlite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ create table genres (
create table movies_genres (
idmovies_genres integer primary key autoincrement,
idmovies integer,
idseries integer,
idgenres integer)

create table keywords (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ create table acted_in (
billing_position integer)

create table genres (
idgenres integer primary key autoincrement,
idgenres integer primary key,
genre text)

create table movies_genres (
Expand All @@ -52,7 +52,7 @@ create table movies_genres (
idgenres integer)

create table keywords (
idkeywords integer primary key autoincrement,
idkeywords integer primary key,
keyword text)

create table movies_keywords (
Expand Down
11 changes: 6 additions & 5 deletions tosql.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ def from_str(type_string):

def mk_schema(name, use_dict = False):
if use_dict:
return "%s/%s.use_dict.schema" % (Options.schema_dir, name)
return "%s/%s.use_dict.sql" % (Options.schema_dir, name)
else:
return "%s/%s.schema" % (Options.schema_dir, name)
return "%s/%s.sql" % (Options.schema_dir, name)


def mk_cache(name):
Expand All @@ -171,9 +171,10 @@ def create_tables(c):
global Options, Database
if Database.type == DatabaseTypes.SQLITE:
dbf = open(mk_schema("sqlite", Options.use_dict))
query_list = dbf.read().split("\n\n")
for query in query_list:
c.execute(query)
if Database.type == DatabaseTypes.MYSQL:
dbf = open(mk_schema("mysql", Options.use_dict))
query_list = dbf.read()
c.executescript(query_list)


def quote_escape(string):
Expand Down

0 comments on commit f03475b

Please sign in to comment.