forked from DebaucheryLibrarian/traxxx
Updated Jules Jordan scraper.
This commit is contained in:
@@ -1552,6 +1552,11 @@ exports.up = (knex) => Promise.resolve()
|
||||
.defaultTo(knex.fn.now());
|
||||
}))
|
||||
.then(() => knex.schema.createTable('random_campaign', (table) => {
|
||||
table.integer('id')
|
||||
.notNullable()
|
||||
.references('id')
|
||||
.inTable('campaigns');
|
||||
|
||||
table.text('banner_id')
|
||||
.references('id')
|
||||
.inTable('banners');
|
||||
@@ -1903,7 +1908,7 @@ exports.up = (knex) => Promise.resolve()
|
||||
CREATE FUNCTION get_random_campaign(min_ratio decimal default 0, max_ratio decimal default 1000.0) RETURNS random_campaign AS $$
|
||||
SELECT * FROM (
|
||||
SELECT DISTINCT ON (CASE WHEN parent_id IS NOT NULL THEN parent_id ELSE entity_id END)
|
||||
banner_id, url, entity_id, affiliate_id, parent_id
|
||||
id, banner_id, url, entity_id, affiliate_id, parent_id
|
||||
FROM (
|
||||
SELECT
|
||||
campaigns.*, entities.parent_id as parent_id
|
||||
|
||||
58
migrations/20230703013413_random_campaign.js
Normal file
58
migrations/20230703013413_random_campaign.js
Normal file
@@ -0,0 +1,58 @@
|
||||
exports.up = async (knex) => {
|
||||
await knex.schema.alterTable('random_campaign', (table) => {
|
||||
table.integer('id')
|
||||
.notNullable()
|
||||
.references('id')
|
||||
.inTable('campaigns');
|
||||
});
|
||||
|
||||
await knex.raw(`
|
||||
CREATE OR REPLACE FUNCTION get_random_campaign(min_ratio decimal default 0, max_ratio decimal default 1000.0) RETURNS random_campaign AS $$
|
||||
SELECT * FROM (
|
||||
SELECT DISTINCT ON (CASE WHEN parent_id IS NOT NULL THEN parent_id ELSE entity_id END)
|
||||
banner_id, url, entity_id, affiliate_id, parent_id, id
|
||||
FROM (
|
||||
SELECT
|
||||
campaigns.*, entities.parent_id as parent_id
|
||||
FROM campaigns
|
||||
LEFT JOIN entities ON entities.id = campaigns.entity_id
|
||||
LEFT JOIN banners ON banners.id = campaigns.banner_id
|
||||
WHERE banner_id IS NOT NULL
|
||||
AND ratio >= min_ratio
|
||||
AND ratio <= max_ratio
|
||||
ORDER BY RANDOM()
|
||||
) random_campaigns
|
||||
) random_banners
|
||||
ORDER BY RANDOM()
|
||||
LIMIT 1;
|
||||
$$ LANGUAGE SQL STABLE;
|
||||
`);
|
||||
};
|
||||
|
||||
exports.down = async (knex) => {
|
||||
await knex.schema.alterTable('random_campaign', (table) => {
|
||||
table.dropColumn('campaign_id');
|
||||
});
|
||||
|
||||
await knex.raw(`
|
||||
CREATE OR REPLACE FUNCTION get_random_campaign(min_ratio decimal default 0, max_ratio decimal default 1000.0) RETURNS random_campaign AS $$
|
||||
SELECT * FROM (
|
||||
SELECT DISTINCT ON (CASE WHEN parent_id IS NOT NULL THEN parent_id ELSE entity_id END)
|
||||
banner_id, url, entity_id, affiliate_id, parent_id
|
||||
FROM (
|
||||
SELECT
|
||||
campaigns.*, entities.parent_id as parent_id
|
||||
FROM campaigns
|
||||
LEFT JOIN entities ON entities.id = campaigns.entity_id
|
||||
LEFT JOIN banners ON banners.id = campaigns.banner_id
|
||||
WHERE banner_id IS NOT NULL
|
||||
AND ratio >= min_ratio
|
||||
AND ratio <= max_ratio
|
||||
ORDER BY RANDOM()
|
||||
) random_campaigns
|
||||
) random_banners
|
||||
ORDER BY RANDOM()
|
||||
LIMIT 1;
|
||||
$$ LANGUAGE SQL STABLE;
|
||||
`);
|
||||
};
|
||||
11
migrations/_20230703000556_campaign_html.js
Normal file
11
migrations/_20230703000556_campaign_html.js
Normal file
@@ -0,0 +1,11 @@
|
||||
exports.up = async (knex) => {
|
||||
await knex.schema.alterTable('banners', (table) => {
|
||||
table.text('html');
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = async (knex) => {
|
||||
await knex.schema.alterTable('banners', (table) => {
|
||||
table.dropColumn('html');
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user