How to rename a database in RethinkDB - rethinkdb

On the api documentation page rethinkdb.com/api/javascript I can only find commands to create, drop and list databases.
But how I can I rename a database in RethinkDB?

You basically have two options:
1. Update the name using the .config method
You can also update the name using the .config method every database and tables has. This would look something like this:
r
.db("db_name")
.config()
.update({name: "new_db_name"})
2. Update the db_config table
You can also execute a query on the db_config table and just do an update on the db you want to change. This would look something like this:
r
.db('rethinkdb')
.table('db_config')
.filter({ name: 'old_db_name' })
.update({ name: 'new_table_name'})

Related

Laravel: Running a database migration on a production server

I have a local repo for development and a production server in Laravel.
When I work locally, as the project grows, so does the DB. Therefore I keep adding new migrations that sometimes change existing tables. Locally I can refresh / recreate tables and seed without worrying.
However when I want to update the production DB where actual data is stored, what's the best method? If I need to update an existing table I cannot just drop and recreate it, as data would be lost. And if I run the migration directly, I get an error like "table already exists". So I end up manually adding the fields in the DB, which I don't think it's the best way to go.
As already mentioned, you can create migrations to update the columns without dropping the tables. And the 'Modifying columns' docs provide a clear explanation for this. However that is docs for modifying columns, if you want to modify tables instead of columns, you can use the 'Updating tables' docs
This uses the SchemaBuilder to do various things, for example, adding columns in an existing table:
Schema::table('table_name'), function ($table) {
$table->string('new_column')->after('existing_column');
// however you can leave the ->after() part out, this just specifies that the
// new column should be insterted after the specified column.
});
Or delete a column from an existing table
Schema::table('table_name'), function ($table) {
$table->dropColumn('new_column');
});
You can also rename but I'll leave it to you to explore the docs further.

Sqitch - single plan row, multiple sql files

I'm looking to move to sqitch, but my team likes their migrations as multiple files. That is, for example, if we create a foreign key and create an index in the same jira ticket, we like PROJ-123-create-fk.sql and PROJ-123-create-index.sql.
I'd like to keep a single row in the sqitch.plan file, so that each jira ticket corresponds to a single row.
Basically, short of adding lines to sqitch.plan, can I do this? Is there a way to "include" other sql files from a master one? Something like
PROJ-123-main.sql
\include PROJ-123-create-fk.sql
\include PROJ-123-create-index.sql
Thanks so much!
The \ir psql directive solved this for me.
in PROJ-123-deploy.sql
\ir PROJ-123-create-fk.sql
\ir PROJ-123-create-index.sql
If the fk and index sql files are in the same directory, they will be executed.
Since you want to store it as a single line in the plan file, it doesn't quite match, but I will explain the method we use below. Maybe there are parts that you want to use in it.
There is a similar situation in my team, but we use sqitch tags. Each version of our application corresponds to a subtask. And each task corresponds to a tag. We create sql files as many as the number of subtasks. Then we combine them in a tag that we created with the name of the main task. In our CI/CD pipeline that we use for the database, we also provide the transition between versions with tags. I wanted to add this method here in case anyone prefers to use a similar structure.
Simple example;
Let's have v2.0 of our application installed and a new table and an index are required for v2.1
We create two subtasks named create table and create index under the main task named v2.1
We create two sql files;
app_v2.1_table_create.sql to create a table, app_v2.1_index_create.sql to create an index.
After that, we create a sqitch tag called v2.1. Notice it has the same name as the main task.

How to delete the ContentType and related db tables in Strapi?

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

Propel ORM: How to save Object only, if such an object doesnt already exist

I'm using the Propel ORM. One of my tables is called "friend" and its entries represent many-to-many-relationships. The table "friend" has to entries:
profile_id
friend_profile_id
These two properties obviously create the PrimaryKey.
Now I would like to update this table, with new Information. So I would like to save new Friend-Entries like so:
$friendCon = new RplFriend();
$friendCon->setProfileId($profile->getId());
$friendCon->setFriendProfileId($friendProfile->getId());
$friendCon->save();
But at this point, I dont know if such an entry already exists. So I get lots of "Duplicate Entry" errors from Propel. What is the most performant way, to only save a new entry, if it doesnt already exist?
Maybe you should try something like:
$friendCon_duplicate = RplFriendQuery::create()->findPK($profile->getId(),$friendProfile->getId());
if($friendCon_duplicate..
set unique index of those 2 fields in your database

Dynamic Data Associate Related Table Value?

I have create a LINQ-to-SQL project in Visual Studio 2010 using Dynamic Data. In this project I have two tables. One is called phones_extension and the other phones_ten. The list of columns in phones_extension looks like this:
id, extension, prefix, did_flag, len, ten_id, restriction_class_id, sfc_id, name_display, building_id, floor, room, phone_id, department_id
In phones_ten it looks like this:
id, name, pbxid
Now, I'd like to be able to somehow make it so that there is an association (or inheritance?) that essentially results in me being able to make a query like phones_extension.ten and it gives me the result of phones_ten.name. Right now I have to get phones_extension.ten_id and then match that against phones_ten.id - I'm trying to get the DBML to handle this translation automatically.
Is this possible?
OK Dave, you need to setup a relatioship in the DB for this to work in Linq to SQL you could just create the relatioship (association in L2S) but there will need to be a primary key on each table anyway to allows edits.

Resources