I need to bake a large project but a requirement is each model has its schema listed at the top as a multi-line comment.
Any ideas ?
Thanks, Alex
Start in your [PATH]/cake/console/templates/classes/model.ctp file.
Manually connect to the database using an old-fashioned php connect string.
Pull the table structure in a "describe" query.
Loop through, print out the table structure in comments.
cake bake...
Related
I haven't found in documentation anything except "syncdb" command which create database tables from scratch. Is there any command to create and run migrations based on ORM model? Like in django? Add field, change type, etc.
No, orm.RunSyncdb(name, force, verbose) and it's command line equivalent only do a small subset of what tools like django's south can do.
Beego's orm can:
Create new tables from scratch
Drop all tables (force = true)
Add new columns as you extend your model
You need to handle dropping columns and any changes to the column parameters used to initially create the table.
Sadly beego doesn't include this feature, but no framework in go (as of today) does.
Instead they all relay that to other libraries to handle.
What you can do however is use goose for migrations:
https://bitbucket.org/liamstask/goose
or any other migration library as discussed in the following thread:
http://www.reddit.com/r/golang/comments/2dlbz5/database_migration_handling_in_go/
Remember that due to the modularity of beego you can also use any another orm (like gorm).
Feel free to look for : avelino/awesome-go in google if you want a list of tools/libs around the go ecosystem.
Yes, you can create migrations in beego now. Example, If you need to create a new table, you can start by creating a new migration file using the bee tool:
bee generate migration create_user_table
This command will create a file inside database/migrations folder. The file name contains the date, time and name of the migration.
For further details you can check this article https://ncona.com/2017/10/database-migrations-in-beego
I am looking for a way to map existing tables in a project with the Eloquent ORM and use them in code. I use a MySQL database and plan to migrate to MSSQL. Any way points are appreciated.
You'll have to do this manually.
i.e., create an eloquent model for each of the tables you want access to in your code using eloquent.
If you don't have timestamps named created_at and updated_at, in your model you can disable those columns.
Manually
If you have a users table you could 'map' it with a user.php file in your models folder like this
class User extends Eloquent {
protected $table = 'users';
public $timestamps = false;
}
Via artisan
You can use Jeffrey Ways Laravel Generators to help streamline the initial creation of your models, however you'll still need to make the timestamp modification manually.
This looks like an old post, but it was edited a couple of days ago, so I don't know if the original author is looking for a solution again, but if someone needs this info, here is a packagist package for Laravel 5 to do what you are asking.
Laravel 5 model generator from existing schema:
https://packagist.org/packages/ignasbernotas/laravel-model-generator
Hope that helps someone!
There is also a Eloquent Model Generator library. It can be used for generating Eloquent models using database tables as a source. Generated model will include relation methods, docblocks for magic field and relations and several additional properties.
Another here: https://github.com/Xethron/migrations-generator.
You'll only want to use these generators for local development, so you don't want to update the production providers array in config/app.php. Instead, add the provider in app/Providers/AppServiceProvider.php.
For more details look here - https://packagist.org/packages/ignasbernotas/laravel-model-generator#user-content-installation
You can also use SQL Server Migration Assistant (SSMA) to port the database to SQL Server, but you will still need to write your own models to match the schema.
http://blogs.msdn.com/b/ssma/
http://www.microsoft.com/en-us/download/details.aspx?id=43688
Still this might help get halfway there, from both sides of the puzzle.
I'm working with Django and I added a new model variable meaning that I need another column in my sqlite3 data base.
I have heard that I'm supposed to use sqlite> , but I am really confused when I start to use it. So, if that is part of the solution, can you be very specific on what to do?
thanks
MORE INFO:
my app is called "livestream" & and my class is "Stream"
I added the model "channel"
returns ---->
DatabaseError: table livestream_stream has no column named channel
You can ALTER TABLE to add a new column in Sqlite3 but not rename it nor drop it. Sqlite3 is a very useful database for bootstrapping your app. But sooner or later, you will need to change to a more robust/flexible database engine, say MySql or Postgresql.
Every time you add a new column to your models using Sqlite, you will need to recreate the schema (as far as I know, when you do migrations with Sqlite to add new columns, south complaints. see below). An approach I like more is use MySql with Django-South from the beginning, where I'm not sure about every aspect of my database.
Django South is an app for doing database migrations. It's very useful and the docs are a good starting point for beginners.
Every time you should make modifications to your database, you should consider them as migrations and use South.
Hope this helps!
*This is not really a programming question. On wordpress front-end I have a custom made form. I want to store the form entries in a database table on wordpress back-end. Is there any way(plugin) to do this.
In order to insert data into a database table, it is a best practice to use $wpdb. The WordPress Codex can provide you with examples and more information to help you proceed.
It's exactly the same as a normal MySQL query using PHP only you're using the wpdb class for some PHP variables. Just output your query string which uses wpdb. If it looks like a normal MySQL query that would work, then it will work with the wpdb.
I am very new to cakePHP but I am a bit knowledgeable with Ruby on Rails. I tried creating a controller using the cake bake command in the console but it said:
Your database does not have any tables
As far as I can remember in rails, it allowed me to create controllers without tables or even without setting up database. What I am trying to do is that I want to create a controller and a view for pages such as Home, About, and Help. I don't think those pages still need a model or a database table. Pls help.
sure you can create controllers and views... even models without tables.
But you can't bake them =D bake is just to read the database and help you create your classes from there. So if you dont have any table, you dont have anything to bake..
For the static pages such as Home, About and Help you could use the PagesController
Cheers!