jw
07/14/2021, 12:44 PMJorge Castillo
07/14/2021, 12:45 PMmbonnin
07/14/2021, 12:48 PMDatabase.Schema.create but jdbc doesn't "record" what version of the schema is currently used so if you run it twice, you'll get an error the second timembonnin
07/14/2021, 12:48 PMJorge Castillo
07/14/2021, 12:48 PMJorge Castillo
07/14/2021, 12:49 PM@Bean
fun provideDataSource(): DataSource =
DataSourceBuilder.create()
.apply {
driverClassName(config.database.driver)
url(config.database.url)
username(config.database.username)
password(config.database.password)
}.build()
@Bean
fun provideJdbcDriver(dataSource: DataSource): JdbcDriver =
dataSource.asJdbcDriver()
@Bean
fun provideSubscriptionsDb(
jdbcDriver: JdbcDriver,
dateTimeAdapter: ColumnAdapter<LocalDateTime, String>
): SubscriptionsDb =
SubscriptionsDb(
jdbcDriver.apply { SubscriptionsDb.Schema.create(this) },
SubscriptionEntity.Adapter(dateTimeAdapter)
)mbonnin
07/14/2021, 12:49 PMmbonnin
07/14/2021, 12:50 PMmbonnin
07/14/2021, 12:51 PMmbonnin
07/14/2021, 12:51 PMJorge Castillo
07/14/2021, 12:52 PMJorge Castillo
07/14/2021, 12:53 PMCREATE TABLE IF NOT EXISTSJorge Castillo
07/14/2021, 12:53 PMmbonnin
07/14/2021, 12:54 PMJorge Castillo
07/14/2021, 1:28 PMV1__base.sql file but still getting the same error:
@Bean
fun provideFlyway(dataSource: DataSource): Flyway =
Flyway.configure().dataSource(dataSource).baselineOnMigrate(true).load()
@Bean
fun provideJdbcDriver(dataSource: DataSource, flyway: Flyway): JdbcDriver =
dataSource.asJdbcDriver().apply {
flyway.migrate()
}Jorge Castillo
07/14/2021, 1:49 PM.sq files might affect, since queries to create tables are automatically added to the Schema following the order of the files.
E.g: Keeping in mind files are sorted in alphabetical order in the file system, if you have the following sq files:
• RepositoryEntity.sq
• SubscriptionEntity.sq
• UserEntity.sq
And SubscriptionEntity.sq references a table created in UserEntity.sq like the userEntity table in my case, when the query to create the subscriptionEntity table is called, the userEntity table is still not created. Is order something that could affect declarations to break in any way?Jorge Castillo
07/14/2021, 1:52 PMpublic override fun create(driver: SqlDriver): Unit {
driver.execute(null, """
|CREATE TABLE IF NOT EXISTS repositoryEntity (
| repository_id SERIAL PRIMARY KEY,
| owner VARCHAR NOT NULL,
| repository VARCHAR NOT NULL
|)
""".trimMargin(), 0)
driver.execute(null, """
|CREATE TABLE IF NOT EXISTS subscriptionEntity (
| subscription_id SERIAL PRIMARY KEY,
| subscribed_at DATE NOT NULL, -- TIMESTAMPTZ is not supported by sqldelight
| user_id SERIAL NOT NULL,
| repository_id SERIAL NOT NULL,
| FOREIGN KEY (user_id) REFERENCES userEntity(user_id) ON DELETE CASCADE,
| FOREIGN KEY (repository_id) REFERENCES repositoryEntity(repository_id) ON DELETE CASCADE
|)
""".trimMargin(), 0)
driver.execute(null, """
|CREATE TABLE IF NOT EXISTS userEntity (
| user_id SERIAL PRIMARY KEY,
| slack_user_id VARCHAR NOT NULL,
| slack_channel_id VARCHAR
|)
""".trimMargin(), 0)
}mbonnin
07/14/2021, 3:50 PM