Schema migrations using peewee to create new models - peewee

I really like how lightweight and simple peewee is for ORM. But now I am trying to implement schema migtations in the database and I feel peewee might be a bit limited on this aspect. From what I understand in the documentation, peewee migrations support altering schema on the exisiting models such as add_not_null, add_column. I am wondering is there any operations from peewee that can be used for adding or deleting models. Or if there is any other libaries that can help on this? Thanks in advance.
Pointing to peewee operations or 3rd party libaries

Peewee itself has facilities for creating and dropping tables:
class MyModel(Model):
...
# Create tables
database.create_tables([MyModel, OtherModel, ...])
# Drop tables
database.drop_tables([MyModel, OtherModel, ...])
http://docs.peewee-orm.com/en/latest/peewee/api.html#Database.create_tables

Related

TypeORM: Migrations first or entity first

I have a bit of debate with my teammate if what is better, my preference is to create the entity first then the migration because it is more productive than manually creating migrations.
What are the pros and cons of the two approaches?
Creating the migrations first then the entity by running typeorm migration:create
Create the entity first then the migrations by running typeorm migration:generate
A good practice to avoid bugs and time wasting is to create entities first to generate the migrations files after using typeorm migration:generate.
Creating the migrations manually using typeorm migration:create is a good practice too but it takes a long time and could be a source of bugs, especially concerning the columns types.
Generating migrations is also useful when you need to alter a table or columns, you don't need to search the modifications on your own.
Finally, you must already know it but never use synchronize in production.

Virtual property in Entity Framework or SQL Server join using view

I have a model that has many navigation properties to other poco models. I was wondering that replacing it with a SQL view that join all these tables by foreign keys into one respecting model to get all data that I need in one trip will boost performance. Any tips will be appreciated.
In your case using an Indexed View likely would improve read-performance, so it's worth evaluating. If you have the ability to alter the database structure then you may also consider using EF's ComplexType feature to map many related classes to a single db row--avoiding the need to join altogether.
When working with an ORM it's important to keep in mind that the design of your C# model and your database typically do not have to be the same; so you can build a performant database as well as a reasonable C# model with minimal compromise.

Doctrine ORM in CodeIgniter - pros and cons?

I'm looking into Doctrine as my ORM for an upcoming CodeIgniter project. I've never used an ORM before, but based on what I have read so far, it's a great thing. So, I'd like to get my hands in it.
Questions:
In your experience, what are the benefits of Doctrine?
I noticed that I can identify certain tables to include created_at and updated_at columns. How beneficial is it to know when a record was created and last updated? Should I do this for all my tables?
Thanks.
I haven't personally used Doctrine, but have been told it works well. My understanding is that it requires a significant amount of setup, and works magically after that.
The ORM I typically use with CodeIgniter is called DataMapper ORM, which is a native CodeIgniter solution. Installation is simple (copying a couple files), setting up models is stupidly easy, the tables are simple, and it uses the existing application's database settings. For all the magic without the setup, I'd recommend DataMapper.
Regarding the use of created_at and updated_at columns, only add those columns when you need to track that anyway, such as a blog post or a system user. Specifying those columns lets the ORM handle those fields, so you don't need to, so whenever you create or update objects created from the database, those fields are updated automatically.

django manual database migration

I am preferring to manually migrate my tables in Django. Because using automated tools puts me in a place where I cannot see the impact. With impact, I mean the the time it takes the db get in synch with my models. Below is a simple example:
class User(models.Model):
first_name = CharField(..)
Let's say I want to add this:
class User(models.Model):
first_name = CharField(..)
last_name = CharField(..)
I will follow the these steps in my production server:
Disable site traffic.
Manually connect to the your DB server, let's say MySQL and add a field to the User table named last_name (make sure it is sync with the SQL generated for the new Model, of course.)
Update your model.
Upload new files, restart traffic.
I have two questions for this scenario:
Is this a preferred/acceptable way for manual db migration in Django?
If I just add a field with a specific default value to the User table by SQL manually, but don't update the model, will I still get DatabaseIntegrity exception?
Thanks in advance,
With all of the schema migration tools, such as south, there are ways of explicitly defining how your models get migrated. The benefits of using a tool such as this are:
Your migrations are stored in your version control system
There's a documented procedure to roll back schema migrations
If another developer joins your project, you can refer that person to the south documentation rather than explaining your own hacky solution to documenting schema migrations.
I think I should just emphasize a point here: Though south has automigration tools, you don't have to use automigration if you're using South.
Is this a preferred/acceptable way for manual db migration in Django?
I would answer no. As #Mike said Django has a reliable and fairly versatile ecosystem of migration tools, the most prominent of which is South. #Mike's answer has the details right.
To answer your second question:
If I just add a field with a specific default value to the User table by SQL manually, but don't update the model, will I still get DatabaseIntegrity exception?
No. Your models will continue to function normally. Of course if you want to do something with the new fields using Django's ORM you'll be better off adding them to the model class.
A side effect of this is that you can migrate legacy database tables by selectively choosing the fields to use in your models.

Many-to-many relationship in .NET RIA services

I have a many-to-many relationship in my database of objects A to B. When i create a domain service the metadata looks fine. A has a collections of Bs, B has a collection of As. So it is correct. However the *.g.cs file generated doesn't have the same relationship.
Is there a way to make it work? I googled some answer to actually generate objects for the association table but i am curious if i can avoid this.
Thanks
In the current release/version of RIA Services, you'll need the association table. We will most definitely be looking into this of course for a future release.
That said, I think often many-to-many relationships often have some interesting data associated with the relationship and as such, the middle table often has a real use, rather than existing for the sake of existing.
Till MS implements it in RIA, you can use http://m2m4ria.codeplex.com/
We have used in one of our Silverlight/RIA projects for User/Role (many-to-many) relationship and worked fine.

Resources