Adding Column Using Subsonic 3.0.0.5 Migration - subsonic

I want to know that How to Insert New Columns to an existing database Table using Subsonic 3.0.0.5 MIGRATIONS.
Basically I want to alter an existing table in MS SqlServer database and add three more columns into it.
Please tell me How I will be able to do it
Regards,
Naveed Khan

Just change your object and the column will be added/updated whatever. So if you have an object called "Post" and add a property, it will be added as a column in the DB.
See this video...
http://subsonicproject.com/docs/Simple_Repo_5_Minute_Demo

It has to do with the conventions of SubSonic.
As the object is singular, it adds the plural to the table (or expects the table to be plural).
So it will expect an object called Order to map to a table called Orders.
There is only two solutions that I can see for you
1) Rename you table to the plural name.
2) Modify Subsonic code to remove the adding of the plural.

Related

Mongoose How to update if exists, based on custom fields. Otherwise insert

I'm building a mongoDB database that holds sales data from multiple different systems. Each system is integrated via an node/mongoose/Express API that I'm creating for the database. Typically, you'd check the id to determine if a record already exists, and insert it if it doesn't. But since the ID from these different sources could technically overlap, I need a system to make sure that a source can only update records that originally came from that source. So I've added a column called "external_ID" where the record id from the source is saved, and another column called "integration ID", which will be unique to the specific system that sends data. But for that idea to work, I'd need to update only if those two columns matches, and otherwise insert a new record. Is that possible with MongoDB, or am I approaching this wrong?
Thank you so much.
Use upsert on update(). It will creates a new document when no document matches the query criteria.
db.collection.update(<query>, <update>, { upsert: true })
You can find more detail at Upsert Behavior documentation

sequelize: retrieve model of a manually created table

If i create tables with sequelize API (sequelize.define), it returns a model object (User in the following example) that i can use to do queries (User.find) and other kind of operations:
var User = sequelize.define('User', {/* ... */})
If i need to create a table in the db without that api, but i need to do it with a pure sql query, is there a way to retrieve the same model object for my manual table and use it like the others?
In sequelize.models i see all my tables but not the custom one.
You need to define a model using define with the tableName property set to your manually defined table.
The DB columns that you want to retrieve as a model's attributes must meet a number of criteria. Each should have a datatype that matches the column's type. They should have the same constraints (cascade, null etc) as the DB columns. The column name should either match what Sequelize automatically generates or be specified manually using field.
Since the table for this model has already been manually created, make sure that it is not sync'ed to the DB. To test that the model you have specified will work the manually specified table you should sync the model to a test database and compare the automatically generated SQL with the manually generated SQL You are using.
This answer is based on the documentation here.

DB2 backup and restore db table preserving foreign key constraints

I'm currently having issue going through a test backup and restore of database table on my development machine for db2. Was never entirely successful. Although I was able to restore all data after a drop and re-create of the table, I wasn't able to reset the foreign key constraint as I got SQL error complaining that keys don't match. Here's my exact steps, I'm sure not entirely the right way to do it, but it does eventually restore the 5423 rows of data:
The process
export to /export/home/dale/comments.ixf of ixf messages /export/home/dale/msg.txt select * from .comments
Note: step 1 exports 5423 rows of data to a location
drop table .comments
import from /export/home/dale/comments.ixf of ixf create into .comments
Note: step 3 here creates the table but does not insert any data rows
load client from /export/home/dale/comments.ixf of ixf modified by identityoverride replace into .comments
Note: up until this step, I'm able to insert the 5423 rows of data in the recreated db table
alter table .comments add FOREIGN KEY (comments_id) REFERENCES .news (article_key)
Note: here alter table fails as db2 complaints that some comments_id does not match article_key
Could anyone help with my problem here? Thanks in advance
The error means that some of the rows you IMPORT into the Comments table refer to rows that do not exist in the News table.
You might not be forming the constraint correctly. The column name "comment_id" sounds like the primary key to the Comments table. You want the foreign key, which matches the primary key of the News table. It might also be called "article_key" or "article_id".
ALTER TABLE Comments
ADD FOREIGN KEY( article_key)
REFERENCES News( article_key);
If "comment_id" is really not the primary key of the "Comments" table, then the problem comes from not backing up and restoring both the News and Comments table at the same time.
You can either EXPORT and IMPORT the News table along with the Comments table, or remove the Comments that refer to missing News rows with something like this
DELETE FROM Comments
WHERE comments_id NOT IN (
SELECT article_key
FROM News
)
Before you do this, you might want to try listing the Comments which would be deleted by the above query
SELECT *
FROM Comments
WHERE comments_id NOT IN (
SELECT article_key
FROM News
)
I found a solution to my problem as well as my comments above,
user980717 resolved my first problem where I set the wrong column as the foreign key
For my 2nd issue, i.e. "SQL0668N Operation not allowed for reason code "1" on table "tablename". SQLSTATE=57016", I need to run the following command "set integrity for niwps.comments immediate checked" to ensure data satisfied all constraints defined in the table. And thanks to all who took the effort in helping me with my problems. Cheers

Copy Column Data - Azure Table Storage

So Azure Table Storage has three default member properties for its TableServiceEntity class, one of which is Timestamp. After release to Production, we now realize we need a CreatedDateTime property instead of Timestamp b/c we have no control over the Timestamp value, which acts more like a "Last Modified" value rather than "Created Date" value.
How can I copy the value in Timestamp currently over to my new property? In SQL, this seems pretty straightforward, but the cloud is a different animal. Thanks.
In Table Storage you have no schema. In a single "table" you can have 10 rows with a C# defined class of Person and 10 rows of class Dog with COMPLETELY different properties.
The reason I am saying this is because there is no schema, so the easiest thing to do would be to "re-insert" the rows as a batch with the new column/property added to the class. You can also do an UPSERT as well:
http://blogs.msdn.com/b/windowsazurestorage/archive/2011/09/15/windows-azure-tables-introducing-upsert-and-query-projection.aspx
If the column is already defined then its easy and u would just do an update, but it sounds like that new column does not exist on the previous rows entered.
If you are using a class, just add the new field for the create date time. Pull all the data down and copy the timestamp to the new field and then call update on the row. If you are already doing inserts and deletes and thigns, should be pretty straightforward.

How to delete a product from m_product table in openbravo

how to delete a particular product from m_product table in openbravo , Because it has triggers and are interlinked with other tables
I don't think doing a SQL delete is a good choice, since there are some tables related with a particular product (like accounting information).
At application level, if the product is already referenced from another table (like an Order), you wont be able to delete it. However, you can always de-activate the record, achieving a logic deletion of the product.
When you delete using database queries, it will automatically prompt you the linked items where it is being used with the table names. You can remove the dependencies there. If you want to automate it, refer the linked items implementation in openbravo and use that as a base to find out where it is linked and remove them.
Thanks,
Shankar
You may use following options
1) Instead of deleting entry you may consider marking product as inactive or discontinued, so that product will not be available/visible on other windows and reports
2) Delete all linked items first, then delete product entry from UI
3) If you are deleting, using SQL statements - first delete all references(linked tables data) or temporarily turn off triggers and delete

Resources