sql

package
v0.0.0-...-5666d16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2017 License: Apache-2.0 Imports: 5 Imported by: 0

README

Overview

This defines the model that Fetcher uses to save the data in the database, and that Transform reads in order to generate the metrics.

The database and the tables are automatically created on the first connection by Gorm. The mapping between the Go objects here and the database rows is also done by Gorm.

Schema

Here is what the final schema looks like:

List of tables in the github database:

+------------------+
| Tables_in_github |
+------------------+
| comments         |
| issue_events     |
| issues           |
| labels           |
+------------------+

comments table:

+--------------------+--------------+------+-----+---------+----------------+
| Field              | Type         | Null | Key | Default | Extra          |
+--------------------+--------------+------+-----+---------+----------------+
| id                 | int(11)      | NO   | PRI | NULL    | auto_increment |
| issue_id           | int(11)      | YES  |     | NULL    |                |
| body               | text         | YES  |     | NULL    |                |
| user               | varchar(255) | YES  |     | NULL    |                |
| comment_created_at | timestamp    | YES  |     | NULL    |                |
| comment_updated_at | timestamp    | YES  |     | NULL    |                |
| pull_request       | tinyint(1)   | YES  |     | NULL    |                |
+--------------------+--------------+------+-----+---------+----------------+

issue_events table:

+------------------+--------------+------+-----+---------+----------------+
| Field            | Type         | Null | Key | Default | Extra          |
+------------------+--------------+------+-----+---------+----------------+
| id               | int(11)      | NO   | PRI | NULL    | auto_increment |
| label            | varchar(255) | YES  |     | NULL    |                |
| event            | varchar(255) | YES  |     | NULL    |                |
| event_created_at | timestamp    | YES  |     | NULL    |                |
| issue_id         | int(11)      | YES  |     | NULL    |                |
| assignee_id      | varchar(255) | YES  |     | NULL    |                |
| actor_id         | varchar(255) | YES  |     | NULL    |                |
| assignee         | varchar(255) | YES  |     | NULL    |                |
| actor            | varchar(255) | YES  |     | NULL    |                |
+------------------+--------------+------+-----+---------+----------------+

issues table:

+------------------+---------------+------+-----+---------+----------------+
| Field            | Type          | Null | Key | Default | Extra          |
+------------------+---------------+------+-----+---------+----------------+
| id               | int(11)       | NO   | PRI | NULL    | auto_increment |
| title            | varchar(1000) | YES  |     | NULL    |                |
| body             | text          | YES  |     | NULL    |                |
| user             | varchar(255)  | YES  |     | NULL    |                |
| assignee         | varchar(255)  | YES  |     | NULL    |                |
| state            | varchar(255)  | YES  |     | NULL    |                |
| comments         | int(11)       | YES  |     | NULL    |                |
| is_pr            | tinyint(1)    | YES  |     | NULL    |                |
| issue_closed_at  | timestamp     | YES  |     | NULL    |                |
| issue_created_at | timestamp     | YES  |     | NULL    |                |
| issue_updated_at | timestamp     | YES  |     | NULL    |                |
+------------------+---------------+------+-----+---------+----------------+

And labels table:

+----------+--------------+------+-----+---------+-------+
| Field    | Type         | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| issue_id | int(11)      | YES  | MUL | NULL    |       |
| name     | varchar(255) | YES  |     | NULL    |       |
+----------+--------------+------+-----+---------+-------+

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comment

type Comment struct {
	ID               int
	IssueID          int
	Body             string `gorm:"type:text"`
	User             string
	CommentCreatedAt time.Time
	CommentUpdatedAt time.Time
	PullRequest      bool
}

Comment is either a pull-request comment or an issue comment.

type Issue

type Issue struct {
	ID             int
	Labels         []Label
	Title          string `gorm:"type:varchar(1000)"`
	Body           string `gorm:"type:text"`
	User           string
	Assignee       *string
	State          string
	Comments       int
	IsPR           bool
	IssueClosedAt  *time.Time
	IssueCreatedAt time.Time
	IssueUpdatedAt time.Time
}

Issue is a pull-request or issue. Its format fits into the ORM

func (*Issue) FindLabels

func (issue *Issue) FindLabels(regex *regexp.Regexp) []Label

FindLabels returns the list of labels matching the regex

type IssueEvent

type IssueEvent struct {
	ID             int
	Label          *string
	Event          string
	EventCreatedAt time.Time
	IssueId        int
	Assignee       *string
	Actor          *string
}

IssueEvent is an event associated to a specific issued. It's format fits into the ORM

type Label

type Label struct {
	IssueID int
	Name    string
}

Label is a tag on an Issue. It's format fits into the ORM.

type MySQLConfig

type MySQLConfig struct {
	Host     string
	Port     int
	Db       string
	User     string
	Password string
}

MySQLConfig is specific to this database

func (*MySQLConfig) AddFlags

func (config *MySQLConfig) AddFlags(cmd *cobra.Command)

AddFlags parses options for database configuration

func (*MySQLConfig) CreateDatabase

func (config *MySQLConfig) CreateDatabase() (*gorm.DB, error)

CreateDatabase for the MySQLConfig

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL