Comments (10)
Not really, but I think they can be useful at some point (especially context). I am not sure, but since it is a public API I would not change the signature without a good reason.
I agree with the context but I'm trying to figure out any future need for bun.Db
. In most, if not all cases, creating migration is done during development phase where one might not have access to database without first spinning up one. One thing I could come up with where database access would be useful is to load templates from database (I'm spit-balling here) and in that case I'm sure a CreateSQLFromDB
function would be a more adequate way of doing it. Or maybe generating migration based on diff between last migration and new database state. Again, separate function might be better.
See below how I suggest to extend the API with options
That sounds good.
It used to work this way, but once I broke something (probably changed db schema name) and the app attempted to initialize a new migrations table and re-run all the migrations from scratch in production environment.
That is an interesting problem. Most of my apps are self-initializing and if I would to change table and locksTable at a later time I would have the same problem. I guess the only solution would be to check if the database has any tables before auto-initializing. But that is database specific.
For the rest of the points not mentioned here I will start working on the PRs
from bun.
Add more code to generated go template like the one bellow since this is a MVP for go migration file.
This was addressed by 98281aa.
from bun.
@isgj yes, probably it should be the default behavior. Empty migrations should work fine and users can delete down migration if they don't need it.
from bun.
@isgj should be done in v0.3.4
from bun.
All of that sounds good 👍 We just need to figure out the details :) I think it will be easier if you split these changes into multiple PRs so we can merge it faster and there is a sense progress being made.
function since they are not used. Is it planned for the future?
Not really, but I think they can be useful at some point (especially context). I am not sure, but since it is a public API I would not change the signature without a good reason. See below how I suggest to extend the API with options.
Make package name configurable for CreateGo migration (and/or item 6.)
What about keeping the existing signature and instead adding an option:
func CreateGo(ctx context.Context, db *bun.DB, name string, opts ...GoOption) error
migrations.CreateGo(ctx, app.DB(), c.Args().Get(0), migrations.WithGoPackage("something"))
This way we can add more options in backwards compatible manner.
Also should not directory string
be a global option?
var Migrations = migrate.NewMigrations(migrate.WithDirectory(directory))
Add a check before migrate if the required migration tables exist, if not, initialize. Quick and dirty way is to run Init(...) on every migration. Might be cheaper to execute then checking first. But speed is not an issue here.
It used to work this way, but once I broke something (probably changed db schema name) and the app attempted to initialize a new migrations table and re-run all the migrations from scratch in production environment.
Luckily for me nothing was broken, but since then I prefer to require explicit initialization. But we can add an option like WithAutoInit()
if you insist.
from bun.
Again, separate function might be better.
Let's try it 👍
Part of the problem is that migrate is a library, but it is used as a CLI program so it complicates things. For example, it makes sense to change Status
function to return a struct, but then the CLI should somehow print that struct.
I try to address that by providing a starter-kit, but it still can be challenging to use the API correctly....
from bun.
@vmihailenco Great!
Then all that remains here is point 6 with maybe point 3:
Add option for adding user template for go and sql migration file creation
Make package name configurable for CreateGo migration
What do you think?
from bun.
Make package name configurable for CreateGo migration
This looks rather straightforward:
migrator.CreateGo(ctx, name, WithPackageName("main"))
Add option for adding user template for go and sql migration file creation
I am not sure about the template, because then we also need to add template data, funcs and so on. What about just allowing to specify migration content:
migrator.CreateGo(ctx, name, WithMigrationContent("go source code here"))
And WithMigrationContent
will ignore WithPackageName
option.
from bun.
Sorry for jumping in and interrupting the discussion. Can there be also an option when creating the sql migration to create also the down
migration.?
from bun.
@vmihailenco excellent work. I think all of the points are resolved so I am closing this. Thanks!
from bun.
Related Issues (20)
- how do i exec multiple queries as a single query?
- regression: models with nested embedded structs not handled properly
- ParseInt Error
- race detected in ```schema.Field.Clone()``` HOT 2
- Issue with BeforeAppendModel when selecting columns to update HOT 1
- Go migrations are not discovered
- Custom sum column on a relation
- In v1.2, about 'unique' tag option in embedded structures HOT 1
- Call BeforeAppendModel on embedded types
- incorrect CTE generation
- Is []int64 supported for Arrays
- Support for DuckDB dialect
- Ambiguous Column Reference Id
- Scan error on column: bun: Scan(unsupported [32]uint8)"
- m2m relations with composite keys
- can't scan 1 (float32) into float32
- Issue: Panic on Bulk Upsert with Pointer Fields in Slice of Interfaces HOT 1
- Documentation Pgx section update HOT 2
- Is it possible to insert a comment before or after a sql query?
- how can i tag index in struct filed?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bun.