Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating tables? #64

Open
clydebarrow opened this issue Dec 10, 2019 · 16 comments
Open

Creating tables? #64

clydebarrow opened this issue Dec 10, 2019 · 16 comments
Labels
enhancement New feature or request

Comments

@clydebarrow
Copy link
Contributor

Is there any support for creating tables from a Ktorm schema? Or do tables have to be manually created using direct SQL commands?

@ashokgelal
Copy link

There is no support for creating tables from a Ktorm schema. I know that @vincentlauvlwj wanted to write an IDE plugin that would help you in creating tables but I don't know the status of it. With some help from @vincentlauvlwj, I ended up writing my own 'migration library' for a web framework that I'm working on.

@vincentlauvlwj
Copy link
Member

As @ashokgelal said, there was no support for creating tables from a Ktorm schema. I'm planning to write an IDE plugin for that but it's still a plan now...

@vincentlauvlwj
Copy link
Member

@ashokgelal Seems you have finished your migration library. Can you share your code? Maybe that will inspire me to some extent.

@ashokgelal
Copy link

ashokgelal commented Dec 12, 2019

Well, it's still in early alpha state but the framework repo is here: https://github.com/ashokgelal/alpas

There is no README only because I'm spending all my energy writing the documentation: https://alpas.dev/docs

The migration/database/Ktorm related code is here: https://github.com/alpas/alpas/tree/master/framework/src/main/kotlin/dev/alpas/ozone

@Ray-Eldath
Copy link
Contributor

Ray-Eldath commented Jan 29, 2020

Comes from Exposed by Jetbrains... it's tight-compose between user's entity and Exposed entity is really tiring to deal with, you even cant create a mock instance of your entity. i guess this is derived from the avoid of using reflection or-so.

i've noticed that ktorm has a very similar descriptive syntax, comparing to exposed. it's looks very nice, thank you for developing such a good framework 😉

i've also noticed seems there's nothing equivalent to ShemaUtils.createNonExisitingTables in exposed which will automatically create/alter table structure based on the table instance you provide, it's very convenient, for you'll liberate from managing the consistent between your database-initialization sql and ktorm descriptive syntax. i'll say maybe this is the last mile of ktorm.


maybe off-topic: is there any way to specify size for columns like varchar? exposed's syntax provide two parameters, as varchar("column name", <size>) while ktorm only has the former, which is really wierd, IMHO.

BTW the translate in exposed, maybe equivalent to your ColumnRegisteration mechanism, but hugely consiser, and easier to use. I think it's worth take a look at. i'll try to port this mechanism into ktorm, hope works well.


Edit: sorry. now I know the missing size is because the auto-creation of tables is not handled by ktorm... but if it's gonna be implemented - deeply hope so, i'll investigate at this as well - it's necessary for creation to work.

@ashokgelal
Copy link

@Ray-Eldath for setting the column size, you can start here: https://github.com/alpas/alpas/blob/master/framework/src/main/kotlin/dev/alpas/ozone/MigratingTable.kt

Since, I've already started allowing migration of a database, very similar to what you have mentioned, I'm more than willing to collaborate on this. If you want to chat further, I'm available on Slack here. Feel free to join and ping me (Vincent is also available there in case we need him to clarify something).

@vincentlauvlwj vincentlauvlwj added the enhancement New feature or request label Feb 2, 2020
@joegasewicz
Copy link

What's the state of this enhancement? I'm new to Ktorm & can't see anywhere in the docs how i can create tables using the DSL.

@michaelfyc
Copy link
Contributor

Is there any update on this after 5 months?

@jonrosner
Copy link

Is it not possible to create tables using ktorm? I am used to calls like .createTableIfNotExist()

@moxisuki
Copy link

使用 ktorm 创建表是不可能的吗?我习惯于像.createTableIfNotExist()这样的调用

i would like to

@seepine
Copy link

seepine commented Oct 14, 2022

@vincentlauvlwj Is there a plan to realize this function? like hibernate can auto create/update tables when entity change, golang gorm also support, it can be seen that it is a very useful function. we have to give up ktorm without this, because our product must support remote upgrade for many customers.

@milgner
Copy link

milgner commented Feb 15, 2023

Unfortunately, creating tables is only part of the picture. Over time, the overall schema will change. Sometimes operations will be as simple as renaming columns, but other times more complex schema or even data migrations might need to happen like adding a table for a new model, extracting data from an existing model into the new tables and then removing columns from the old tables.
This in itself is a completely different set of challenges from the ORM itself and although a straightforward integration with a tool like that would be highly advantageous, it's understandable if the ktorm team doesn't jump onto it.
I'd personally suggest looking into Flyway or Liquibase for schema maintenance and leave ktorm to do object-relational mapping.

@mjovanc
Copy link

mjovanc commented Feb 26, 2023

Would be great if there was some tool that could take the Ktorm entity definitions and generate a Liquibase changelog file. So we don't have to manually create those. Just a thought.

@mleonhard
Copy link

How about adding a method to check that the connected database schema is compatible with the ktorm definition? Then we could use Flyway for migrations and run the check in CI/staging to catch mistakes.

@mjovanc
Copy link

mjovanc commented Feb 28, 2023

How about adding a method to check that the connected database schema is compatible with the ktorm definition? Then we could use Flyway for migrations and run the check in CI/staging to catch mistakes.

That is a very good idea. I wish I had the time to look at implementing this, would be very useful.

@lightsing
Copy link

Good if can have migrations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests