sql

package
v0.0.0-...-71304e1 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 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    |       |
+----------+--------------+------+-----+---------+-------+

And assignees table:

+------------+--------------+------+-----+---------+-------+
| Field      | Type         | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| repository | varchar(255) | YES  |     | NULL    |       |
| issue_id   | varchar(255) | YES  |     | 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 Assignee

type Assignee struct {
	Repository string
	IssueID    string
	Name       string
}

Assignee is assigned to an issue.

type Comment

type Comment struct {
	Repository       string `gorm:"primary_key;index:repo_created"`
	ID               string `gorm:"primary_key"`
	IssueID          string
	Body             string `gorm:"type:text"`
	User             string
	CommentCreatedAt time.Time `gorm:"index:repo_created"`
	CommentUpdatedAt time.Time
	PullRequest      bool
}

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

type Issue

type Issue struct {
	Repository     string `gorm:"primary_key"`
	ID             string `gorm:"primary_key"`
	Labels         []Label
	Assignees      []Assignee
	Title          string `gorm:"type:varchar(1000)"`
	Body           string `gorm:"type:text"`
	User           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 {
	Repository     string `gorm:"primary_key;index:repo_created"`
	ID             string `gorm:"primary_key"`
	Label          *string
	Event          string
	EventCreatedAt time.Time `gorm:"index:repo_created"`
	IssueId        string
	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 {
	Repository string
	IssueID    string
	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