Skip to content

Commit 29d5680

Browse files
authored
Varchar (#916)
Varchar
2 parents 8954e18 + b1c782e commit 29d5680

16 files changed

+124
-173
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

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

2022
### Fixed

Diff for: blobs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type blobsTable struct {
3636
// BlobsSchema is the schema for the blobs table.
3737
var BlobsSchema = sql.Schema{
3838
{Name: "repository_id", Type: sql.Text, Nullable: false, Source: BlobsTableName},
39-
{Name: "blob_hash", Type: sql.Text, Nullable: false, Source: BlobsTableName},
39+
{Name: "blob_hash", Type: sql.VarChar(40), Nullable: false, Source: BlobsTableName},
4040
{Name: "blob_size", Type: sql.Int64, Nullable: false, Source: BlobsTableName},
4141
{Name: "blob_content", Type: sql.Blob, Nullable: false, Source: BlobsTableName},
4242
}

Diff for: commit_blobs.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ type commitBlobsTable struct {
1919
// CommitBlobsSchema is the schema for the commit blobs table.
2020
var CommitBlobsSchema = sql.Schema{
2121
{Name: "repository_id", Type: sql.Text, Source: CommitBlobsTableName},
22-
{Name: "commit_hash", Type: sql.Text, Source: CommitBlobsTableName},
23-
{Name: "blob_hash", Type: sql.Text, Source: CommitBlobsTableName},
22+
{Name: "commit_hash", Type: sql.VarChar(40), Source: CommitBlobsTableName},
23+
{Name: "blob_hash", Type: sql.VarChar(40), Source: CommitBlobsTableName},
2424
}
2525

2626
var _ Table = (*commitBlobsTable)(nil)

Diff for: commit_files.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ type commitFilesTable struct {
2424
// CommitFilesSchema is the schema for the commit trees table.
2525
var CommitFilesSchema = sql.Schema{
2626
{Name: "repository_id", Type: sql.Text, Source: CommitFilesTableName},
27-
{Name: "commit_hash", Type: sql.Text, Source: CommitFilesTableName},
27+
{Name: "commit_hash", Type: sql.VarChar(40), Source: CommitFilesTableName},
2828
{Name: "file_path", Type: sql.Text, Source: CommitFilesTableName},
29-
{Name: "blob_hash", Type: sql.Text, Source: CommitFilesTableName},
30-
{Name: "tree_hash", Type: sql.Text, Source: CommitFilesTableName},
29+
{Name: "blob_hash", Type: sql.VarChar(40), Source: CommitFilesTableName},
30+
{Name: "tree_hash", Type: sql.VarChar(40), Source: CommitFilesTableName},
3131
}
3232

3333
func newCommitFilesTable(pool *RepositoryPool) Indexable {

Diff for: commit_trees.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ type commitTreesTable struct {
2121
// CommitTreesSchema is the schema for the commit trees table.
2222
var CommitTreesSchema = sql.Schema{
2323
{Name: "repository_id", Type: sql.Text, Source: CommitTreesTableName},
24-
{Name: "commit_hash", Type: sql.Text, Source: CommitTreesTableName},
25-
{Name: "tree_hash", Type: sql.Text, Source: CommitTreesTableName},
24+
{Name: "commit_hash", Type: sql.VarChar(40), Source: CommitTreesTableName},
25+
{Name: "tree_hash", Type: sql.VarChar(40), Source: CommitTreesTableName},
2626
}
2727

2828
func newCommitTreesTable(pool *RepositoryPool) Indexable {

Diff for: commits.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ type commitsTable struct {
2020
// CommitsSchema is the schema for the commits table.
2121
var CommitsSchema = sql.Schema{
2222
{Name: "repository_id", Type: sql.Text, Nullable: false, Source: CommitsTableName},
23-
{Name: "commit_hash", Type: sql.Text, Nullable: false, Source: CommitsTableName},
23+
{Name: "commit_hash", Type: sql.VarChar(40), Nullable: false, Source: CommitsTableName},
2424
{Name: "commit_author_name", Type: sql.Text, Nullable: false, Source: CommitsTableName},
25-
{Name: "commit_author_email", Type: sql.Text, Nullable: false, Source: CommitsTableName},
25+
{Name: "commit_author_email", Type: sql.VarChar(254), Nullable: false, Source: CommitsTableName},
2626
{Name: "commit_author_when", Type: sql.Timestamp, Nullable: false, Source: CommitsTableName},
2727
{Name: "committer_name", Type: sql.Text, Nullable: false, Source: CommitsTableName},
28-
{Name: "committer_email", Type: sql.Text, Nullable: false, Source: CommitsTableName},
28+
{Name: "committer_email", Type: sql.VarChar(254), Nullable: false, Source: CommitsTableName},
2929
{Name: "committer_when", Type: sql.Timestamp, Nullable: false, Source: CommitsTableName},
3030
{Name: "commit_message", Type: sql.Text, Nullable: false, Source: CommitsTableName},
31-
{Name: "tree_hash", Type: sql.Text, Nullable: false, Source: CommitsTableName},
32-
{Name: "commit_parents", Type: sql.Array(sql.Text), Nullable: false, Source: CommitsTableName},
31+
{Name: "tree_hash", Type: sql.VarChar(40), Nullable: false, Source: CommitsTableName},
32+
{Name: "commit_parents", Type: sql.Array(sql.VarChar(40)), Nullable: false, Source: CommitsTableName},
3333
}
3434

3535
func newCommitsTable(pool *RepositoryPool) *commitsTable {

Diff for: docs/assets/gitbase-schema.png

22.8 KB
Loading

Diff for: docs/assets/gitbase_model.mwb

531 Bytes
Binary file not shown.

Diff for: docs/using-gitbase/schema.md

+81-81
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,33 @@ This table will return all the [remotes](https://git-scm.com/book/en/v2/Git-Basi
3838

3939
### refs
4040
``` sql
41-
+---------------+------+
42-
| name | type |
43-
+---------------+------+
44-
| repository_id | TEXT |
45-
| ref_name | TEXT |
46-
| commit_hash | TEXT |
47-
+---------------+------+
41+
+---------------+-------------+
42+
| name | type |
43+
+---------------+-------------+
44+
| repository_id | TEXT |
45+
| ref_name | TEXT |
46+
| commit_hash | VARCHAR(40) |
47+
+---------------+-------------+
4848
```
4949
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.
5050

5151
### commits
5252
``` sql
53-
+---------------------+-----------+
54-
| name | type |
55-
+---------------------+-----------+
56-
| repository_id | TEXT |
57-
| commit_hash | TEXT |
58-
| commit_author_name | TEXT |
59-
| commit_author_email | TEXT |
60-
| commit_author_when | TIMESTAMP |
61-
| committer_name | TEXT |
62-
| committer_email | TEXT |
63-
| committer_when | TIMESTAMP |
64-
| commit_message | TEXT |
65-
| tree_hash | TEXT |
66-
| commit_parents | JSON |
67-
+---------------------+-----------+
53+
+---------------------+--------------+
54+
| name | type |
55+
+---------------------+--------------+
56+
| repository_id | TEXT |
57+
| commit_hash | VARCHAR(40) |
58+
| commit_author_name | TEXT |
59+
| commit_author_email | VARCHAR(254) |
60+
| commit_author_when | TIMESTAMP |
61+
| committer_name | TEXT |
62+
| committer_email | VARCHAR(254) |
63+
| committer_when | TIMESTAMP |
64+
| commit_message | TEXT |
65+
| tree_hash | TEXT |
66+
| commit_parents | JSON |
67+
+---------------------+--------------+
6868
```
6969

7070
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.
@@ -73,14 +73,14 @@ Commits contains all the [commits](https://git-scm.com/book/en/v2/Git-Internals-
7373
7474
### blobs
7575
```sql
76-
+---------------+-------+
77-
| name | type |
78-
+---------------+-------+
79-
| repository_id | TEXT |
80-
| blob_hash | TEXT |
81-
| blob_size | INT64 |
82-
| blob_content | BLOB |
83-
+---------------+-------+
76+
+---------------+--------------+
77+
| name | type |
78+
+---------------+--------------+
79+
| repository_id | TEXT |
80+
| blob_hash | VARCHAR(40) |
81+
| blob_size | INT64 |
82+
| blob_content | BLOB |
83+
+---------------+--------------+
8484
```
8585

8686
This table exposes blob objects, that are the content without path from files.
@@ -89,33 +89,33 @@ This table exposes blob objects, that are the content without path from files.
8989
9090
### tree_entries
9191
```sql
92-
+-----------------+------+
93-
| name | type |
94-
+-----------------+------+
95-
| repository_id | TEXT |
96-
| tree_entry_name | TEXT |
97-
| blob_hash | TEXT |
98-
| tree_hash | TEXT |
99-
| tree_entry_mode | TEXT |
100-
+-----------------+------+
92+
+-----------------+-------------+
93+
| name | type |
94+
+-----------------+-------------+
95+
| repository_id | TEXT |
96+
| tree_entry_name | TEXT |
97+
| blob_hash | VARCHAR(40) |
98+
| tree_hash | VARCHAR(40) |
99+
| tree_entry_mode | VARCHAR(16) |
100+
+-----------------+-------------+
101101
```
102102

103103
`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).
104104

105105

106106
### files
107107
```sql
108-
+-----------------+-------+
109-
| name | type |
110-
+-----------------+-------+
111-
| repository_id | TEXT |
112-
| file_path | TEXT |
113-
| blob_hash | TEXT |
114-
| tree_hash | TEXT |
115-
| tree_entry_mode | TEXT |
116-
| blob_content | BLOB |
117-
| blob_size | INT64 |
118-
+-----------------+-------+
108+
+-----------------+--------------+
109+
| name | type |
110+
+-----------------+--------------+
111+
| repository_id | TEXT |
112+
| file_path | TEXT |
113+
| blob_hash | VARCHAR(40) |
114+
| tree_hash | VARCHAR(40) |
115+
| tree_entry_mode | VARCHAR(16) |
116+
| blob_content | BLOB |
117+
| blob_size | INT64 |
118+
+-----------------+--------------+
119119
```
120120

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

127127
### commit_blobs
128128
```sql
129-
+---------------+------+
130-
| name | type |
131-
+---------------+------+
132-
| repository_id | TEXT |
133-
| commit_hash | TEXT |
134-
| blob_hash | TEXT |
135-
+---------------+------+
129+
+---------------+-------------+
130+
| name | type |
131+
+---------------+-------------+
132+
| repository_id | TEXT |
133+
| commit_hash | VARCHAR(40) |
134+
| blob_hash | VARCHAR(40) |
135+
+---------------+-------------+
136136
```
137137

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

140140
### commit_trees
141141
```sql
142-
+---------------+------+
143-
| name | type |
144-
+---------------+------+
145-
| repository_id | TEXT |
146-
| commit_hash | TEXT |
147-
| tree_hash | TEXT |
148-
+---------------+------+
142+
+---------------+-------------+
143+
| name | type |
144+
+---------------+-------------+
145+
| repository_id | TEXT |
146+
| commit_hash | VARCHAR(40) |
147+
| tree_hash | VARCHAR(40) |
148+
+---------------+-------------+
149149
```
150150

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

153153
### commit_files
154154
```sql
155-
+---------------+------+
156-
| name | type |
157-
+---------------+------+
158-
| repository_id | TEXT |
159-
| commit_hash | TEXT |
160-
| file_path | TEXT |
161-
| blob_hash | TEXT |
162-
| tree_hash | TEXT |
163-
+---------------+------+
155+
+----------------------+------+
156+
| name | type |
157+
+----------------------+------+
158+
| repository_id | TEXT |
159+
| commit_hash | VARCHAR(40) |
160+
| file_path | TEXT |
161+
| blob_hash | VARCHAR(40) |
162+
| tree_hash | VARCHAR(40) |
163+
+---------------+-------------+
164164
```
165165

166166
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.
167167

168168
### ref_commits
169169
```sql
170-
+---------------+-------+
171-
| name | type |
172-
+---------------+-------+
173-
| repository_id | TEXT |
174-
| commit_hash | TEXT |
175-
| ref_name | TEXT |
176-
| history_index | INT64 |
177-
+---------------+-------+
170+
+---------------+--------------+
171+
| name | type |
172+
+---------------+--------------+
173+
| repository_id | TEXT |
174+
| commit_hash | VARCHAR(40) |
175+
| ref_name | TEXT |
176+
| history_index | INT64 |
177+
+---------------+--------------+
178178
```
179179

180180
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.

Diff for: files.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ type filesTable struct {
2323
var FilesSchema = sql.Schema{
2424
{Name: "repository_id", Type: sql.Text, Source: "files"},
2525
{Name: "file_path", Type: sql.Text, Source: "files"},
26-
{Name: "blob_hash", Type: sql.Text, Source: "files"},
27-
{Name: "tree_hash", Type: sql.Text, Source: "files"},
28-
{Name: "tree_entry_mode", Type: sql.Text, Source: "files"},
26+
{Name: "blob_hash", Type: sql.VarChar(40), Source: "files"},
27+
{Name: "tree_hash", Type: sql.VarChar(40), Source: "files"},
28+
{Name: "tree_entry_mode", Type: sql.VarChar(16), Source: "files"},
2929
{Name: "blob_content", Type: sql.Blob, Source: "files"},
3030
{Name: "blob_size", Type: sql.Int64, Source: "files"},
3131
}

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/src-d/go-borges v0.0.0-20190628121335-da12a84d60fd
2020
github.com/src-d/go-git v4.7.0+incompatible
2121
github.com/src-d/go-git-fixtures v3.5.1-0.20190605154830-57f3972b0248+incompatible
22-
github.com/src-d/go-mysql-server v0.4.1-0.20190703140603-bbae51955887
22+
github.com/src-d/go-mysql-server v0.4.1-0.20190704102044-bbae51955887
2323
github.com/stretchr/testify v1.3.0
2424
github.com/uber-go/atomic v1.4.0 // indirect
2525
github.com/uber/jaeger-client-go v2.16.0+incompatible

0 commit comments

Comments
 (0)