(file) Return to make-database CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / viewcvs

File: [RizwankCVS] / geekymedia_web / viewcvs / make-database (download)
Revision: 1.1.1.1 (vendor branch), Sat Feb 12 13:10:06 2005 UTC (19 years, 3 months ago) by rizwank
Branch: rizwank, MAIN
CVS Tags: start, HEAD
Changes since 1.1: +0 -0 lines
Imported source/web tree

#!/usr/bin/python
# -*- Mode: python -*-
#
# Copyright (C) 2000-2001 The ViewCVS Group. All Rights Reserved.
#
# By using this file, you agree to the terms and conditions set forth in
# the LICENSE.html file which can be found at the top level of the ViewCVS
# distribution or at http://viewcvs.sourceforge.net/license-1.html.
#
# Contact information:
#   Greg Stein, PO Box 760, Palo Alto, CA, 94302
#   gstein@lyra.org, http://viewcvs.sourceforge.net/
#
# -----------------------------------------------------------------------
#
# administrative program for CVSdb; creates a clean database in
# MySQL 3.22 or later
#
# -----------------------------------------------------------------------
#

import os, sys, string
import popen2

INTRO_TEXT = """\
This script creates the database and tables in MySQL used by the ViewCVS
checkin database.  You will be prompted for: database user, database user
password, and database name.  This script will use mysql to create the
database for you.  You will then need to set the appropriate parameters
in your viewcvs.conf file under the [cvsdb] section.
"""

DATABASE_SCRIPT="""\
DROP DATABASE IF EXISTS <dbname>;
CREATE DATABASE <dbname>;

USE <dbname>;

DROP TABLE IF EXISTS branches;
CREATE TABLE branches (
  id mediumint(9) DEFAULT '0' NOT NULL auto_increment,
  branch varchar(64) binary DEFAULT '' NOT NULL,
  PRIMARY KEY (id),
  UNIQUE branch (branch)
);

DROP TABLE IF EXISTS checkins;
CREATE TABLE checkins (
  type enum('Change','Add','Remove'),
  ci_when datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
  whoid mediumint(9) DEFAULT '0' NOT NULL,
  repositoryid mediumint(9) DEFAULT '0' NOT NULL,
  dirid mediumint(9) DEFAULT '0' NOT NULL,
  fileid mediumint(9) DEFAULT '0' NOT NULL,
  revision varchar(32) binary DEFAULT '' NOT NULL,
  stickytag varchar(255) binary DEFAULT '' NOT NULL,
  branchid mediumint(9) DEFAULT '0' NOT NULL,
  addedlines int(11) DEFAULT '0' NOT NULL,
  removedlines int(11) DEFAULT '0' NOT NULL,
  descid mediumint(9),
  UNIQUE repositoryid (repositoryid,dirid,fileid,revision),
  KEY ci_when (ci_when),
  KEY whoid (whoid),
  KEY repositoryid_2 (repositoryid),
  KEY dirid (dirid),
  KEY fileid (fileid),
  KEY branchid (branchid)
);

DROP TABLE IF EXISTS descs;
CREATE TABLE descs (
  id mediumint(9) DEFAULT '0' NOT NULL auto_increment,
  description text,
  hash bigint(20) DEFAULT '0' NOT NULL,
  PRIMARY KEY (id),
  KEY hash (hash)
);

DROP TABLE IF EXISTS dirs;
CREATE TABLE dirs (
  id mediumint(9) DEFAULT '0' NOT NULL auto_increment,
  dir varchar(128) binary DEFAULT '' NOT NULL,
  PRIMARY KEY (id),
  UNIQUE dir (dir)
);

DROP TABLE IF EXISTS files;
CREATE TABLE files (
  id mediumint(9) DEFAULT '0' NOT NULL auto_increment,
  file varchar(128) binary DEFAULT '' NOT NULL,
  PRIMARY KEY (id),
  UNIQUE file (file)
);

DROP TABLE IF EXISTS people;
CREATE TABLE people (
  id mediumint(9) DEFAULT '0' NOT NULL auto_increment,
  who varchar(32) binary DEFAULT '' NOT NULL,
  PRIMARY KEY (id),
  UNIQUE who (who)
);

DROP TABLE IF EXISTS repositories;
CREATE TABLE repositories (
  id mediumint(9) DEFAULT '0' NOT NULL auto_increment,
  repository varchar(64) binary DEFAULT '' NOT NULL,
  PRIMARY KEY (id),
  UNIQUE repository (repository)
);

DROP TABLE IF EXISTS tags;
CREATE TABLE tags (
  repositoryid mediumint(9) DEFAULT '0' NOT NULL,
  branchid mediumint(9) DEFAULT '0' NOT NULL,
  dirid mediumint(9) DEFAULT '0' NOT NULL,
  fileid mediumint(9) DEFAULT '0' NOT NULL,
  revision varchar(32) binary DEFAULT '' NOT NULL,
  UNIQUE repositoryid (repositoryid,dirid,fileid,branchid,revision),
  KEY repositoryid_2 (repositoryid),
  KEY dirid (dirid),
  KEY fileid (fileid),
  KEY branchid (branchid)
);
"""

if __name__ == "__main__":
    print INTRO_TEXT
    
    user = raw_input("MySQL User: ")
    passwd = raw_input("MySQL Password: ")
    dbase = raw_input("ViewCVS Database Name [default: ViewCVS]: ")
    if not dbase:
        dbase = "ViewCVS"

    cmd = "{ mysql --user=%s --password=%s ; } 2>&1" % (user, passwd)
    dscript = string.replace(DATABASE_SCRIPT, "<dbname>", dbase)

    pipes = popen2.Popen3(cmd)
    pipes.tochild.write(dscript)
    pipes.tochild.close()
    print pipes.fromchild.read()
    status = pipes.wait()

    if status:
        print "[ERROR] the database did not create sucessfully."
        sys.exit(1)

    print "Database created successfully."
    sys.exit(0)
    

Rizwan Kassim
Powered by
ViewCVS 0.9.2