How to update the date column and increase the counter? - laravel

I have to increase the counter and update the updated_at column. I used following code to increase the counter based on the click but I am not sure how to update date column.
Link::where('role', $id)->increment('counter');

It should be the default value of updated_at is ON UPDATE CURRENT_TIMESTAMP.
`updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
Or,
`updated_at` TIMESTAMP NULL DEFAULT ON UPDATE CURRENT_TIMESTAMP,

Related

How to configure Oracle Column's DefaultValue And Collate Value

In Oracle 19c, I want to specify the default value of a column and the collate property at the same time.
create table id_table(
name varchar2(64) collate binary_ai,
id varchar2(8) collate binary_ci
);
insert into id_table values('Christopher', 'ABCD1234');
SELECT collation(name), collation(id) from id_table;
COLLATION(NAME)
COLLATION(ID)
BINARY_AI
BINARY_CI
It was well specified as intended.
but,
create table id_table2(
name char default 'Y' collate binary_ai,
id varchar2(8)
);
insert into id_table2 values('c', 'ABCD1234');
SELECT collation(name), collation(id) from id_table2;
COLLATION(NAME)
COLLATION(ID)
USING_NLS_COMP
USING_NLS_COMP
If you specify the default value and collate together, an unintended value is specified.
The intent was to expect the same values as in the first example.
Are DEFAULT VALUE and COLLATE mutually exclusive?

stripe recurring payments per cycle for quantity plans

Dears,
I'm working on a system with tow plans interval monthly and yearly subscriptions
the cost of the subscription per quantity so the customer can increment and decrement the subscriptions as he wants
I have a subscriptions table with the following column
CREATE TABLE `subscriptions` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`company_company_id` int NOT NULL,
`plan_name` varchar(191) NOT NULL,
`product_id` varchar(100) DEFAULT NULL,
`subscription_stripe_id` varchar(191) NOT NULL,
`stripe_status` varchar(191) NOT NULL,
`stripe_price_id` varchar(191) DEFAULT NULL,
`quantity` int DEFAULT NULL,
`amount` float DEFAULT NULL,
`trial_ends_at` timestamp NULL DEFAULT NULL,
`ended_at` timestamp NULL DEFAULT NULL,
`ends_at` timestamp NULL DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`interval` varchar(20) DEFAULT NULL,
`current_period_start` timestamp NULL DEFAULT NULL,
`current_period_end` timestamp NULL DEFAULT NULL,
`cancelled_at` timestamp NULL DEFAULT NULL,
`cancellation_reason_id` int DEFAULT NULL,
`cancellation_notes` text,
PRIMARY KEY (`id`),
KEY `subscriptions_company_id_stripe_status_index` (`stripe_status`)
) ENGINE=InnoDB AUTO_INCREMENT=75 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
I need to make a monthly report for invoices for each subscription cycle
my questions what happened exactly when renewing subscriptions current_period_start and
current_period_end column is updated to the new subscriptions cycle how I can get invoices per cycle because the subscriptions start and end date not always start from the first day of the month
thanks
The simplest thing would be to list the Invoices that belong to a particular Subscription [1]. Those monthly/yearly Invoices will be listed in reverse chronological order. The topmost Invoice will always be the on created for the current billing period (assuming licensing and not usage reported billing).
You could also listen for webhook events for invoice.created events as the Subscription cycles and process the Invoices in your own system as they arrive [2].
[1] https://stripe.com/docs/api/invoices/list#list_invoices-subscription
[2] https://stripe.com/docs/webhooks

How to select only those rows which are greater than modified time using spring data jpa

For Example ,
I have created a table ,
CREATE DATABASE es_db;
USE es_db;
DROP TABLE IF EXISTS es_table;
CREATE TABLE es_table (
id BIGINT(20) UNSIGNED NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY unique_id (id),
client_name VARCHAR(32) NOT NULL,
modification_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
insertion_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
Now assume i have to select those data which are greater than time i give as input .
consider this query for example,
SELECT *, UNIX_TIMESTAMP(modification_time) AS unix_ts_in_secs FROM es_table WHERE (UNIX_TIMESTAMP(modification_time) > :sql_last_modifiedvalue AND modification_time < NOW()) ORDER BY modification_time ASC
Is there away to translate the same to native query ? i can achieve the same with jdbctemplate but would like to know if this is possible with native query?

Why is TIMESTAMP DEFAULT CURRENT_TIMESTAMP not set?

I defined an Oracle table this way:
CREATE TABLE MANUAL_CORRECTION
(
ID NUMBER(19,0) NOT NULL,
MODIFIED TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
MODIFIED_BY NUMBER(19,0) NOT NULL,
MODIFIED_PROPERTY VARCHAR2(20 BYTE) NOT NULL,
OLD_VALUE VARCHAR2(20 BYTE) NOT NULL,
NEW_VALUE VARCHAR2(20 BYTE) NOT NULL,
CONSTRAINT MODIFIED_BY_FK FOREIGN KEY (MODIFIED_BY) REFERENCES BENUTZER (ID) ENABLE,
PRIMARY KEY (ID)
);
I want to insert records via JPA which works well but the MODIFIED column stays always NULL although I specified that it should be set to the system timestamp by default.
How can I achieve that the system timestamp is set whenever a new entity/record is persisted?
Here is how I defined the column/entity property:
#Column(name = "MODIFIED", nullable = false, updatable = false, insertable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
private Timestamp modified;
I think your JPA is sending explicitly NULL as the value for the column and The default value is applied only when you do not specify it in an insert column clause.
Insert into <table> (col1, col2) values (1, null) -- col2 - default value will not be applied
Insert into <table> (col1) values (1) -- col2 - default value will be applied
So if you want to apply default value even when NULL is explicitly passed as a value of the column, you can use the new feature of the Oracle 12c i.e. default on null
Refer this doc
Cheers!!

Column that will dysplay current date in grocery_crud CodeIgniter

In grocery_crud and Code Igniter in table Employees I have column today(dd/mm/yyyy). How to set column to display current date. Please help me.
With MySQL you can't do this with a Date but with a Timestamp column, and you add 'CURRENT_TIMESTAMP' as the default value.
That said as of MySQL version 5.6.5 you can do it with :
CREATE TABLE foo (
`creation_time` DATETIME DEFAULT CURRENT_TIMESTAMP,
`modification_time` DATETIME ON UPDATE CURRENT_TIMESTAMP
)
as explained here :
https://stackoverflow.com/a/10603198/1226118

Resources