Doctrine Connection export() and export option in yml - doctrine

i got a (or rather 2) small question(s)
from doctrine manual
$conn->export->createTable('test', array('name' => array('type' => 'string')));
$conn->execute('INSERT INTO test (name) VALUES (?)', array('jwage'));
whats the $conn->export() abt. i mean, the export(). whats it for?
has it got any thing to do with the export option in the data fixtures yaml file? whats does export and validate do? any where i can get a list of available "attributes" and what they do?
User:
columns:
...
attributes:
export: all
validate: true

It has nothing to do with the attributes.
It is just the module/class that handels database creation/altering.
look at this page in the manual:
http://www.doctrine-project.org/documentation/manual/1_2/en/database-abstraction-layer#export
The Export module provides methods for managing database structure. The methods can be grouped based on their responsibility: create, edit (alter or update), list or delete (drop) database elements.

Related

Using the Serverless Framework with AWS, Sequelize's auto-generated table aliases differ depending on environment (offline vs. Lambda)

I'm using the Serverless Framework with the serverless-offline plugin. I've been developing an AWS Lambda function offline and so far haven't had many huge problems.
I need to do a more complicated SQL query, and so I opted to use the literal method to write some pure SQL. I checked the log and saw that Sequelize (with sequelize-typescript) was assigning aliases to the table names so that they matched the model names (or in the case of table relationships, the aliases matched the key that the relationship was assigned to. So I wrote my SQL accordingly. I ended up with the following.
const customer = await this.findOne({
include: [Coupons, CustomersInfo],
where: {
email_address: {
[Op.eq]: sql.literal(`binary '${email}'`)
},
authorization_level: {
[Op.ne]: 6
},
[Op.and]: [
sql.literal(`
CASE WHEN '${coupon_code}' is null || '${coupon_code}' = ''
THEN (coupon.coupon_flag !=2 || coupon.coupon_flag is null)
ELSE Customers.referral = '${coupon_code}'
END
`)
]
},
});
So again, to clarify, in the logs I could see that the customers table was being aliased to "Customers" and the coupon table was being aliased to "coupon".
I did a bunch of local development offline using the serverless-offline plugin, just put it up on lambda and... it doesn't work.
It doesn't work because for some reason on Lambda the same customers table is getting aliased as "l". If I edit my hard coded query to reference the customers table as "l", then it works fine on Lambda... but it stops working offline because offline it is getting aliased as "Customers".
Is there any way to force Sequelize to alias the table as a certain name? Or something I can do to normalize the names between the two environments?
I figured this out while I was typing up the question, so I'll go ahead and write out the answer.
The problem was that my code was getting minimized when it was deployed as a Lambda function. Here is the relevant documentation about minification and sequelize-typescript. Once minimized, the derived table alias was becoming "l" (and in a subsequent attempt "b"). In order to force the table alias to be a specific name even after minimization, you need to define modelName when making your model class. Example below.
#Table({
tableName: "customers",
modelName: "xyz",
})
export class Customers extends Model {
// The rest of your column definitions here...
}
The xyz will become the name that the table is aliased to in the raw SQL that is generated.

how to override index query during runtime and update the table laravel-nova

in my use case, I need more than one text box for searching in more than two fields in the index view at the same time, because there too much data, laravel-nova provide only one out of the box, so if there is a way that I can add search in a card and update the index query in run time it will be great, and if there are any other solutions for this problem I would appreciate it.
Laravel Migration:
Create the migration files to set up index queries.
In the function, wherever you needed, use the below command to run the migration.
Artisan::call('migrate', array('--path' => 'app/migrations', '--force' => true));
Here, you can also specify the migration file name like,
Artisan::call('migrate', array('--path' => 'app/migrations/create_index.php', '--force' => true));

CakePHP 3 sessions table in database

I have some questions regarding having CakePHP 3 sessions table stored in the database:
1) Is there a way to remname the table from sessions to a different name? If yes, where should I specify the new name?
2) Similarly to question 1: Is there a way to remname the names of colums in sessions table, so that CakePHP would still operate correctly?
3) Is there a simple way to add even the most basic encription of the data column of sessions table?
So I will cite the database session docs and then also provide some answers. The answers in the docs are more complete.
Specify the model you want to use by including a 'model' key.
'Session' => [
'defaults' => 'database',
'handler' => [
'engine' => 'DatabaseSession',
'model' => 'MyCustomSessions'
]
]
The DatabaseSession handler appears to hard code 'data' and some of the other columns. However, you can (and should) extend that class if you want to do something special
Based on what you want to do it appears creating your own SessionHandler is the way to go. It is quite simple to do and it is outlined in the docs.
My best advice would to take a peek at cake's DatabaseSession. It seems that your requirements are special and it is probably your best course of action.

How to rename a database in 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'})

Magento eav entity setup failing - Can't create table

I am trying to set up a custom entity in Magento 1.7.0.0, following alan storms article about it, but with this simple install script, it tells me that "Can't create table: eavblog_posts".
My install script is deadsimple and looks like this:
<?php
$installer = $this;
$installer->addEntityType('complexworld_eavblogpost',
Array(
'entity_model'=>'complexworld/eavblogpost',
'attribute_model'=>'',
'table'=>'complexworld/eavblogpost',
'increment_model'=>'',eav/entity_increment_numeric
'increment_per_store'=>'0'
));
$installer->createEntityTables(
$this->getTable('complexworld/eavblogpost')
);
How can i get my install script working? Is this a known magento bug?
In my case, the issue was due to a bug with the createEntityTables() method in Magento 1.7/1.12
In their answer to this bug report, the Magento team recommend commenting out line 417 from lib/Varien/Db/Adapter/Pdo/Mysql.php:
$this->_checkDdlTransaction($sql);
Instead, I would recommend following the advice in Zachary Schuessler's post and either
1) copying the createEntityTables() method to your own file (Your/Module/Model/Resource/Setup.php) and commenting out the transaction methods...
or
2) writing an abstracted query in order to keep transactions:
// Example of MySQL API
/**
* Create table array('catalog/product', 'decimal')
*/
$table = $installer->getConnection()
->newTable($installer->getTable(array('catalog/product', 'decimal')))
->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'identity' => true,
'nullable' => false,
'primary' => true,
), 'Value ID')
->addColumn(...
First of all, this line is wrong:
'increment_model'=>'',eav/entity_increment_numeric
It needs to be inside the quotes.
Failing that there are some bugs in the installer functions of the latest version.
Go into your database using phpMyAdmin or similar and check to see if any of the tables already exist. If they do, delete them. Also delete the module's record in core_resource.
Try again.
Then there's a step in here I cant remember off the top of my head (useful, I know, but I'll try and remember it tonight and edit this).
Once the tables have been created, if you look at the foreign key assignments for the type tables (int, text char etc) you'll notice that the entity_id field is looking at eav_entity.entity_id. This needs to change to your eavblogpost_entity table.
You might also notice that the eavblogpost_entity.entity_id field is INT(11), when all the foreign key references are INT(10). Change the eavblogpost_entity.entity_id field to INT(10) manually.
The only way around all of this is to override the createEntityTables() function with one that works, or create all the tables manually. Here's a good resource to help you through that parthttp://inchoo.net/ecommerce/magento/creating-an-eav-based-models-in-magento/
Mess around with all of these as you go and I'm sure you'll stumble across the step that you have to do that I've forgotten. Sorry!

Resources