Skip to content

Commit

Permalink
Varchar (#916)
Browse files Browse the repository at this point in the history
Varchar
  • Loading branch information
ajnavarro authored Jul 5, 2019
2 parents 8954e18 + b1c782e commit 29d5680
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 173 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Errors now report the repository causing the error, if possible.
- Now non rooted siva files support old siva rooted repositories.
- Switch some types of known or maximum length (mostly hashes and emails)
to VarChar with a size.
- Traces now have a root span.

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type blobsTable struct {
// BlobsSchema is the schema for the blobs table.
var BlobsSchema = sql.Schema{
{Name: "repository_id", Type: sql.Text, Nullable: false, Source: BlobsTableName},
{Name: "blob_hash", Type: sql.Text, Nullable: false, Source: BlobsTableName},
{Name: "blob_hash", Type: sql.VarChar(40), Nullable: false, Source: BlobsTableName},
{Name: "blob_size", Type: sql.Int64, Nullable: false, Source: BlobsTableName},
{Name: "blob_content", Type: sql.Blob, Nullable: false, Source: BlobsTableName},
}
Expand Down
4 changes: 2 additions & 2 deletions commit_blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ type commitBlobsTable struct {
// CommitBlobsSchema is the schema for the commit blobs table.
var CommitBlobsSchema = sql.Schema{
{Name: "repository_id", Type: sql.Text, Source: CommitBlobsTableName},
{Name: "commit_hash", Type: sql.Text, Source: CommitBlobsTableName},
{Name: "blob_hash", Type: sql.Text, Source: CommitBlobsTableName},
{Name: "commit_hash", Type: sql.VarChar(40), Source: CommitBlobsTableName},
{Name: "blob_hash", Type: sql.VarChar(40), Source: CommitBlobsTableName},
}

var _ Table = (*commitBlobsTable)(nil)
Expand Down
6 changes: 3 additions & 3 deletions commit_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ type commitFilesTable struct {
// CommitFilesSchema is the schema for the commit trees table.
var CommitFilesSchema = sql.Schema{
{Name: "repository_id", Type: sql.Text, Source: CommitFilesTableName},
{Name: "commit_hash", Type: sql.Text, Source: CommitFilesTableName},
{Name: "commit_hash", Type: sql.VarChar(40), Source: CommitFilesTableName},
{Name: "file_path", Type: sql.Text, Source: CommitFilesTableName},
{Name: "blob_hash", Type: sql.Text, Source: CommitFilesTableName},
{Name: "tree_hash", Type: sql.Text, Source: CommitFilesTableName},
{Name: "blob_hash", Type: sql.VarChar(40), Source: CommitFilesTableName},
{Name: "tree_hash", Type: sql.VarChar(40), Source: CommitFilesTableName},
}

func newCommitFilesTable(pool *RepositoryPool) Indexable {
Expand Down
4 changes: 2 additions & 2 deletions commit_trees.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type commitTreesTable struct {
// CommitTreesSchema is the schema for the commit trees table.
var CommitTreesSchema = sql.Schema{
{Name: "repository_id", Type: sql.Text, Source: CommitTreesTableName},
{Name: "commit_hash", Type: sql.Text, Source: CommitTreesTableName},
{Name: "tree_hash", Type: sql.Text, Source: CommitTreesTableName},
{Name: "commit_hash", Type: sql.VarChar(40), Source: CommitTreesTableName},
{Name: "tree_hash", Type: sql.VarChar(40), Source: CommitTreesTableName},
}

func newCommitTreesTable(pool *RepositoryPool) Indexable {
Expand Down
10 changes: 5 additions & 5 deletions commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ type commitsTable struct {
// CommitsSchema is the schema for the commits table.
var CommitsSchema = sql.Schema{
{Name: "repository_id", Type: sql.Text, Nullable: false, Source: CommitsTableName},
{Name: "commit_hash", Type: sql.Text, Nullable: false, Source: CommitsTableName},
{Name: "commit_hash", Type: sql.VarChar(40), Nullable: false, Source: CommitsTableName},
{Name: "commit_author_name", Type: sql.Text, Nullable: false, Source: CommitsTableName},
{Name: "commit_author_email", Type: sql.Text, Nullable: false, Source: CommitsTableName},
{Name: "commit_author_email", Type: sql.VarChar(254), Nullable: false, Source: CommitsTableName},
{Name: "commit_author_when", Type: sql.Timestamp, Nullable: false, Source: CommitsTableName},
{Name: "committer_name", Type: sql.Text, Nullable: false, Source: CommitsTableName},
{Name: "committer_email", Type: sql.Text, Nullable: false, Source: CommitsTableName},
{Name: "committer_email", Type: sql.VarChar(254), Nullable: false, Source: CommitsTableName},
{Name: "committer_when", Type: sql.Timestamp, Nullable: false, Source: CommitsTableName},
{Name: "commit_message", Type: sql.Text, Nullable: false, Source: CommitsTableName},
{Name: "tree_hash", Type: sql.Text, Nullable: false, Source: CommitsTableName},
{Name: "commit_parents", Type: sql.Array(sql.Text), Nullable: false, Source: CommitsTableName},
{Name: "tree_hash", Type: sql.VarChar(40), Nullable: false, Source: CommitsTableName},
{Name: "commit_parents", Type: sql.Array(sql.VarChar(40)), Nullable: false, Source: CommitsTableName},
}

func newCommitsTable(pool *RepositoryPool) *commitsTable {
Expand Down
Binary file modified docs/assets/gitbase-schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/gitbase_model.mwb
Binary file not shown.
162 changes: 81 additions & 81 deletions docs/using-gitbase/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,33 @@ This table will return all the [remotes](https://git-scm.com/book/en/v2/Git-Basi

### refs
``` sql
+---------------+------+
| name | type |
+---------------+------+
| repository_id | TEXT |
| ref_name | TEXT |
| commit_hash | TEXT |
+---------------+------+
+---------------+-------------+
| name | type |
+---------------+-------------+
| repository_id | TEXT |
| ref_name | TEXT |
| commit_hash | VARCHAR(40) |
+---------------+-------------+
```
This table contains all hash [git references](https://git-scm.com/book/en/v2/Git-Internals-Git-References) and the symbolic reference `HEAD` from all the repositories.

### commits
``` sql
+---------------------+-----------+
| name | type |
+---------------------+-----------+
| repository_id | TEXT |
| commit_hash | TEXT |
| commit_author_name | TEXT |
| commit_author_email | TEXT |
| commit_author_when | TIMESTAMP |
| committer_name | TEXT |
| committer_email | TEXT |
| committer_when | TIMESTAMP |
| commit_message | TEXT |
| tree_hash | TEXT |
| commit_parents | JSON |
+---------------------+-----------+
+---------------------+--------------+
| name | type |
+---------------------+--------------+
| repository_id | TEXT |
| commit_hash | VARCHAR(40) |
| commit_author_name | TEXT |
| commit_author_email | VARCHAR(254) |
| commit_author_when | TIMESTAMP |
| committer_name | TEXT |
| committer_email | VARCHAR(254) |
| committer_when | TIMESTAMP |
| commit_message | TEXT |
| tree_hash | TEXT |
| commit_parents | JSON |
+---------------------+--------------+
```

Commits contains all the [commits](https://git-scm.com/book/en/v2/Git-Internals-Git-Objects#_git_commit_objects) from all the references from all the repositories, not duplicated by repository. Note that you can have the same commit in several repositories. In that case the commit will appear two times on the table, one per repository.
Expand All @@ -73,14 +73,14 @@ Commits contains all the [commits](https://git-scm.com/book/en/v2/Git-Internals-
### blobs
```sql
+---------------+-------+
| name | type |
+---------------+-------+
| repository_id | TEXT |
| blob_hash | TEXT |
| blob_size | INT64 |
| blob_content | BLOB |
+---------------+-------+
+---------------+--------------+
| name | type |
+---------------+--------------+
| repository_id | TEXT |
| blob_hash | VARCHAR(40) |
| blob_size | INT64 |
| blob_content | BLOB |
+---------------+--------------+
```

This table exposes blob objects, that are the content without path from files.
Expand All @@ -89,33 +89,33 @@ This table exposes blob objects, that are the content without path from files.
### tree_entries
```sql
+-----------------+------+
| name | type |
+-----------------+------+
| repository_id | TEXT |
| tree_entry_name | TEXT |
| blob_hash | TEXT |
| tree_hash | TEXT |
| tree_entry_mode | TEXT |
+-----------------+------+
+-----------------+-------------+
| name | type |
+-----------------+-------------+
| repository_id | TEXT |
| tree_entry_name | TEXT |
| blob_hash | VARCHAR(40) |
| tree_hash | VARCHAR(40) |
| tree_entry_mode | VARCHAR(16) |
+-----------------+-------------+
```

`tree_entries` table contains all the objects from all the repositories that are [tree objects](https://git-scm.com/book/en/v2/Git-Internals-Git-Objects#_git_commit_objects).


### files
```sql
+-----------------+-------+
| name | type |
+-----------------+-------+
| repository_id | TEXT |
| file_path | TEXT |
| blob_hash | TEXT |
| tree_hash | TEXT |
| tree_entry_mode | TEXT |
| blob_content | BLOB |
| blob_size | INT64 |
+-----------------+-------+
+-----------------+--------------+
| name | type |
+-----------------+--------------+
| repository_id | TEXT |
| file_path | TEXT |
| blob_hash | VARCHAR(40) |
| tree_hash | VARCHAR(40) |
| tree_entry_mode | VARCHAR(16) |
| blob_content | BLOB |
| blob_size | INT64 |
+-----------------+--------------+
```

`files` is an utility table mixing `tree_entries` and `blobs` to create files. It includes the file path.
Expand All @@ -126,55 +126,55 @@ Queries to this table are expensive and they should be done carefully (applying

### commit_blobs
```sql
+---------------+------+
| name | type |
+---------------+------+
| repository_id | TEXT |
| commit_hash | TEXT |
| blob_hash | TEXT |
+---------------+------+
+---------------+-------------+
| name | type |
+---------------+-------------+
| repository_id | TEXT |
| commit_hash | VARCHAR(40) |
| blob_hash | VARCHAR(40) |
+---------------+-------------+
```

This table represents the relation between commits and blobs. With this table you can obtain all the blobs contained on a commit object.

### commit_trees
```sql
+---------------+------+
| name | type |
+---------------+------+
| repository_id | TEXT |
| commit_hash | TEXT |
| tree_hash | TEXT |
+---------------+------+
+---------------+-------------+
| name | type |
+---------------+-------------+
| repository_id | TEXT |
| commit_hash | VARCHAR(40) |
| tree_hash | VARCHAR(40) |
+---------------+-------------+
```

This table represents the relation between commits and trees. With this table you can obtain all the tree entries contained on a commit object.

### commit_files
```sql
+---------------+------+
| name | type |
+---------------+------+
| repository_id | TEXT |
| commit_hash | TEXT |
| file_path | TEXT |
| blob_hash | TEXT |
| tree_hash | TEXT |
+---------------+------+
+----------------------+------+
| name | type |
+----------------------+------+
| repository_id | TEXT |
| commit_hash | VARCHAR(40) |
| file_path | TEXT |
| blob_hash | VARCHAR(40) |
| tree_hash | VARCHAR(40) |
+---------------+-------------+
```

This table represents the relation between commits and [files](#files). Using this table, you can obtain all the files related to a certain commit object.

### ref_commits
```sql
+---------------+-------+
| name | type |
+---------------+-------+
| repository_id | TEXT |
| commit_hash | TEXT |
| ref_name | TEXT |
| history_index | INT64 |
+---------------+-------+
+---------------+--------------+
| name | type |
+---------------+--------------+
| repository_id | TEXT |
| commit_hash | VARCHAR(40) |
| ref_name | TEXT |
| history_index | INT64 |
+---------------+--------------+
```

This table allow us to get the commit history from a specific reference name. `history_index` column represents the position of the commit from a specific reference.
Expand Down
6 changes: 3 additions & 3 deletions files.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ type filesTable struct {
var FilesSchema = sql.Schema{
{Name: "repository_id", Type: sql.Text, Source: "files"},
{Name: "file_path", Type: sql.Text, Source: "files"},
{Name: "blob_hash", Type: sql.Text, Source: "files"},
{Name: "tree_hash", Type: sql.Text, Source: "files"},
{Name: "tree_entry_mode", Type: sql.Text, Source: "files"},
{Name: "blob_hash", Type: sql.VarChar(40), Source: "files"},
{Name: "tree_hash", Type: sql.VarChar(40), Source: "files"},
{Name: "tree_entry_mode", Type: sql.VarChar(16), Source: "files"},
{Name: "blob_content", Type: sql.Blob, Source: "files"},
{Name: "blob_size", Type: sql.Int64, Source: "files"},
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/src-d/go-borges v0.0.0-20190628121335-da12a84d60fd
github.com/src-d/go-git v4.7.0+incompatible
github.com/src-d/go-git-fixtures v3.5.1-0.20190605154830-57f3972b0248+incompatible
github.com/src-d/go-mysql-server v0.4.1-0.20190703140603-bbae51955887
github.com/src-d/go-mysql-server v0.4.1-0.20190704102044-bbae51955887
github.com/stretchr/testify v1.3.0
github.com/uber-go/atomic v1.4.0 // indirect
github.com/uber/jaeger-client-go v2.16.0+incompatible
Expand Down
Loading

0 comments on commit 29d5680

Please sign in to comment.