Fix mariadb utf8 encoding..

This commit is contained in:
Hubert Van De Walle 2020-08-13 20:39:29 +02:00
parent 24aabd494e
commit e65a4e10d6
4 changed files with 49 additions and 2 deletions

View File

@ -1,12 +1,23 @@
package be.simplenotes.persistance package be.simplenotes.persistance
import be.simplenotes.shared.config.DataSourceConfig
import org.flywaydb.core.Flyway import org.flywaydb.core.Flyway
import javax.sql.DataSource import javax.sql.DataSource
internal class DbMigrationsImpl(private val dataSource: DataSource) : DbMigrations { internal class DbMigrationsImpl(
private val dataSource: DataSource,
private val dataSourceConfig: DataSourceConfig
) : DbMigrations {
override fun migrate() { override fun migrate() {
val migrationDir = when {
dataSourceConfig.jdbcUrl.contains("mariadb") -> "db/migration/mariadb"
else -> "db/migration/other"
}
Flyway.configure() Flyway.configure()
.dataSource(dataSource) .dataSource(dataSource)
.locations(migrationDir)
.load() .load()
.migrate() .migrate()
} }

View File

@ -30,7 +30,7 @@ private fun hikariDataSource(conf: DataSourceConfig): HikariDataSource {
val persistanceModule = module { val persistanceModule = module {
single<UserRepository> { UserRepositoryImpl(get()) } single<UserRepository> { UserRepositoryImpl(get()) }
single<NoteRepository> { NoteRepositoryImpl(get()) } single<NoteRepository> { NoteRepositoryImpl(get()) }
single<DbMigrations> { DbMigrationsImpl(get()) } single<DbMigrations> { DbMigrationsImpl(get(), get()) }
single<DataSource> { hikariDataSource(get()) } single<DataSource> { hikariDataSource(get()) }
single { Database.connect(get<DataSource>()) } single { Database.connect(get<DataSource>()) }
} }

View File

@ -0,0 +1,36 @@
create table Users
(
id int auto_increment primary key,
username varchar(50) not null,
password varchar(255) not null,
constraint username unique (username)
) character set 'utf8mb4'
collate 'utf8mb4_general_ci';
create table Notes
(
uuid binary(16) not null primary key,
title varchar(50) not null,
markdown mediumtext not null,
html mediumtext not null,
user_id int not null,
updated_at datetime null,
constraint Notes_fk_user foreign key (user_id) references Users (id) on delete cascade
) character set 'utf8mb4'
collate 'utf8mb4_general_ci';
create index user_id on Notes (user_id);
create table Tags
(
id int auto_increment primary key,
name varchar(50) not null,
note_uuid binary(16) not null,
constraint Tags_fk_note foreign key (note_uuid) references Notes (uuid) on delete cascade
) character set 'utf8mb4'
collate 'utf8mb4_general_ci';
create index note_uuid on Tags (note_uuid);