Skip to content
Snippets Groups Projects
Commit 86481177 authored by Christian Pointner's avatar Christian Pointner
Browse files

added workarounds for sql error 1071

parent e48e95f2
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,7 @@ $ go get gitlab.servus.at/autoradio/tank/...
Create configuration file see:
https://gitlab.servus.at/autoradio/tank/blob/master/contrib/sample-cfg.yaml
Make sure that the directory pointed to by ```store.path``` exists and is writeable
Make sure that the directory pointed to by `store.path` exists and is writeable
for the user running the daemon
And then run the `tank` binary:
......@@ -24,7 +24,7 @@ $ $GOPATH/bin/tank --config config.yaml run --listen localhost:8000
### Problem with MariaDB on Debian 9 (stretch)
If you start ```tank``` for the first time you may get the following error message:
If you start `tank` for the first time you may get the following error message:
```
running database migrations failed: Error 1071: Specified key was too long; max key length is 767 bytes
......@@ -52,8 +52,8 @@ You may run the daemon using the following command:
$ ./contrib/run.sh
```
This is using ```contrib/sample-cfg.yaml``` and depends on a mysql or postgres server
running on localhost. You may use the scripts inside ```contrib/``` to start docker
This is using `contrib/sample-cfg.yaml` and depends on a mysql or postgres server
running on localhost. You may use the scripts inside `contrib/` to start docker
containers for this purpose.
### mysql
......@@ -102,5 +102,5 @@ After the daemon has ran the initial migrations you may check out the schema of
$$$ psql < info.sql
```
Once you are done with the database you can stop the server by pressing ```CTRL-C``` inside the
Once you are done with the database you can stop the server by pressing `CTRL-C` inside the
terminal of the server.
drop database tank;
create database tank;
-- create database tank CHARACTER SET utf8 COLLATE utf8_general_ci;
grant all privileges on tank.* to 'tank'@'%' identified by 'aura';
use tank;
# MariaDB `Error 1071: Specified key was too long`
tba...
## Background
`tank` stores groups using it's name as primary key. Since this is a string it
by default is mapped to a `VARCHAR(255)` inside the database.
Starting with Debian 9 (stretch) MariaDB is installed instead of mySQL. Debian also
switched to `utf8mb4` as the default character set in an attempt to support Emoji's
stored as utf-8 characters in the database.
This means that a `VARCHAR(255)` is now 1021 bytes long which exceeds the maximum
length (767 bytes) for primary key indices when `innodb` is used (also the default since quite
some time).
## Possible Workarounds
There are several possible workarounds for the problem:
* create the database using `utf8` (not `utf8mb4`):
When creating the database use the following command:
```mysql
create database tank CHARACTER SET utf8 COLLATE utf8_general_ci;
```
This means you won't be able to use Emoji's in File Metadata.
* Debian has [backported](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=886756) some
changes to the MariaDB version in Debian Stretch. Because of this it is possible to switch
to the new innodb layout which is the default for newer version of MariaDB as well as mySQL.
You can do this by adding the following to the `[mysqld]` section of
`/etc/mysql/mariadb.conf.d/50-server.cnf`:
```ini
innodb_file_format = Barracuda
innodb_file_per_table = On
innodb_large_prefix = On
innodb_default_row_format = dynamic
```
* consider switching to another DBMS:
* `tank` also works with postgres
* you may use the mySQL Community Packages from [Oracle](https://dev.mysql.com/doc/refman/5.7/en/linux-installation-debian.html)
* [Percona Server](https://www.percona.com/software/mysql-database/percona-server) is drop-in replacement for mySQL
* if for some reason none of the above is applicable as a last resort you can apply the patch below.
This limits the length for group names to 191 characters which is just short enough to not exceed the limit.
```patch
diff --git a/store/types.go b/store/types.go
index 8576c7b..df99125 100644
--- a/store/types.go
+++ b/store/types.go
@@ -69,7 +69,7 @@ func (e ErrInvalidMetadataField) Error() string {
//******* Groups
type Group struct {
- Name string `json:"name" gorm:"primary_key"`
+ Name string `json:"name" gorm:"primary_key;size:191"`
CreatedAt time.Time `json:"created"`
UpdatedAt time.Time `json:"updated"`
}
@@ -169,7 +169,7 @@ type File struct {
ID uint64 `json:"id" gorm:"primary_key"`
CreatedAt time.Time `json:"created"`
UpdatedAt time.Time `json:"updated"`
- GroupName string `json:"group" gorm:"not null;index"`
+ GroupName string `json:"group" gorm:"not null;index;size:191"`
Group Group `json:"-" gorm:"association_foreignkey:Name"`
Source FileSource `json:"source" gorm:"embedded;embedded_prefix:source__"`
Metadata FileMetadata `json:"metadata" gorm:"embedded;embedded_prefix:metadata__"`
@@ -194,7 +194,7 @@ type Playlist struct {
ID uint64 `json:"id" gorm:"primary_key"`
CreatedAt time.Time `json:"created"`
UpdatedAt time.Time `json:"updated"`
- GroupName string `json:"group" gorm:"not null;index"`
+ GroupName string `json:"group" gorm:"not null;index;size:191"`
Group Group `json:"-" gorm:"association_foreignkey:Name"`
Entries []PlaylistEntry `json:"entries,omitempty"`
}
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment