I want to rename an index in Laravel 5.
In a previous migration a column was created for table named a like so:
$table->unsignedInteger('foo')->index('blah');
I want to rename the index so that it uses the default Laravel notation.
i.e. I want to rename the blah index to a_blah.
I know how to rename a normal column, like so:
$table->renameColumn('from', 'to');
But the documentation does not mention how to rename indexes.
How can I do this?
UPDATE
It seems that Laravel does not support this natively. Please upvote the issue:
https://github.com/laravel/internals/issues/443
Laravel 5.6 now supports renaming indexes:
$table->renameIndex('from', 'to')
https://laravel.com/docs/5.6/migrations#renaming-indexes
Old Answer for Laravel <= 5.5
As #KuKec mentioned, it seems Laravel does not have native support for renaming indexes. But you can use raw SQL. For example in MySQL it would be like so:
DB::statement('RENAME INDEX old_index TO new_index');
This would also likely be more efficient than dropping and re-indexing (especially on large databases).
I have also created an issue for the feature request so this is better supported. Please upvote it here: https://github.com/laravel/internals/issues/443
I think Laravel doesn't support any method for renaming index, you should drop the old index blah
$table->dropIndex('blah');
and make new one with desired name a_blah.
$table->index('foo', 'a_blah');
You should first:
$table->dropIndex('your_full_name_index')
then do
$table->index('new_index_name')
Related
Can anyone help me to automatically save the history of all changed columns in a model to a history column in the same table as JSON format with column(s) name, original value, changed to, changed by?
I am looking for Traits like centralized function to use in all models.
I am using Laravel 8 with PostgreSQL.
This answer is maybe outdated since it is Laravel 4. But if it works, it is quickest way to insert log in DB wherever save() method is called for that model.
https://stackoverflow.com/a/20694395/13893004
I am using Strapi v3.0.0-beta.18.7
How to delete the ContentType and the related tables from DB ?
I tried the command below, but it is not deleting the db tables.
DELETE http://localhost:1337/content-type-builder/content-types/application::CONTENT_TYPE_NAME.CONTENT_TYPE_NAME
To delete the content-type and related db-tables in Strapi,
You can delete the folder inside /api folder having same name as your content-type
Suppose if you want to delete the "product" content type, you can delete the product folder inside of /api
The database's tables sync is not managed in the Content Type Builder plugin.
By default, Strapi doesn't delete anything from your database structure.
Strapi is customizable but you will not be able to update this.
Here is an issue that talks about this topic - https://github.com/strapi/strapi/issues/1114
The answers above are really helpful but don't explain, how you would actually go about deleting the table manually.
Suppose you run a local default installation with sqlite, you can find your database at .tmp/data.db. To connect to it, you will need a tool that you can get from sqlite directly:
https://sqlite.org/download.html
I guess you can add it to the PATH, but since I am a beginner and I just wanted it to work, i put the sqlite3.exe directly in the folder of the database and ran it.
To open the database, I used .open data.db and tested it with .tables which showed me all the tables that strapi created for me but didn't delete.
To ensure that I found the right table (recipe-cuisine) i looked at the content using .headers on followed by SELECT * FROM "recipe-cuisine";.
I finally deleted the whole table using DROP TABLE "recipe-cuisine";.
There is an awesome documentation on how to do other operations here: https://www.sqlitetutorial.net/
I hope that helps other beginners who struggle to delete the tables. If anybody has suggestions or helpful links with more information, that would be great!
Lets assume you need remove abc collection.
WARNING
Be sure you created backup and there are not other collections that contains abc substring.
Then you need execute commands:
DELETE FROM `users-permissions_permission` WHERE `controller` LIKE '%abc%';
DELETE FROM strapi_permission WHERE `subject` LIKE '%abc%';
DELETE FROM core_store WHERE `key` LIKE '%abc%';
DELETE FROM upload_file_morph WHERE related_type LIKE '%abc%';
DROP TABLE abc;
Then you need execute also:
rm -rf api/abc
Additional notes:
take care about plural names
be sure that there are no relations with other tables in other case you will see error
TypeError: Cannot read property 'globalId' of undefined
I am working on a Joomla 3.2.1 site and the client, without thinking, entered in the same alias for all articles, instead of letting the system use the article title. So now if I want to turn on SEF URL's we are going to have 404 issues in the future.
I want to resave or regenerate all article aliases at once (batch).
Is there a way to do it? in the MYSQL DB maybe?
Thank you in advance.
$alias = JApplication::stringURLSafe($article->title);
Joomla will generate the alias when saving the article. I am not aware of any batch joomla feature to regenerate all the aliases and I would also be interested to know about this.
If no other batch solution exists, you should do manually the updates to these fields.
In the database, you could run update queries for all your articles, but you must type each update query one by one.
The update query for a single row would look like:
UPDATE jos_content
SET alias='my-new-alias-name'
WHERE id='{id-of-the-article}'
For multiple rows at once, you could do something like this:
UPDATE jos_content
SET alias = CASE id
WHEN 1 THEN 'alias1'
WHEN 2 THEN 'alias2'
WHEN 3 THEN 'alias3'
END
WHERE id IN (1,2,3)
What you could do is delete the alias data from all of your articles in the database using mysql. Then make a tag, like "fixalias." Using the batch processing feature tag all of the articles with that tag.
This will run store() for all of your articles and automatically generate the aliases. Then delete the tag from the tag manager.you ar
A similar strategy would involve also deleting all the aliases but batch moving (don't copy) your articles to a temporary category and then moving them back.
Mongoid.default_session.database_names gives me an array of database names. I want to delete a specific database. How would I do that?
Mongoid.default_session.drop() always seems to drop the default database even if I override the current database using Mongoid.override_database("test_database")
What am I missing?
In Mongoid v2.0.2
Mongoid.purge!
Rdoc: Mongoid.purge!
Have you tried a combination of Session.use and Session.drop?
Examples: http://mongoid.org/en/moped/docs/driver.html
If I have tables in doctrine for user_1, user_2, etc. is there a way to dynamically set the table name in Doctrine for a single User model?
It's weird, I know. I'm trying to create an interface to a WordPress database (because WP has little to no API for directly accessing posts), and WP creates duplicate tables for each site, so there's a wp_posts, wp_comments, wp_2_posts, wp_2_comments, etc.
Here's what I ended up doing:
$post = new WordPressPost();
$post->setTableName('wp_'.$user_id.'_posts');
If it could, you would have to run migrations for each added/deleted user.
I am curious; why would you EVER need something like that?
I don't know how WP works, but here is the thing; each site should use it's OWN database, not to share it with others.