added advertising

This commit is contained in:
SlimusMinus
2026-09-23 23:34:05 +03:00
parent 05d93d6b0a
commit 942cd09585
83 changed files with 2546 additions and 46 deletions

View File

@@ -1,3 +1,6 @@
ffmpeg:
binary-path: C:\ffmpeg\ffmpeg-9.0.2-essentials_build\bin\ffmpeg.exe
spring:
servlet:
multipart:
@@ -29,6 +32,7 @@ spring:
minio:
endpoint: ${MINIO_ENDPOINT:http://localhost:9010}
bucket: ${MINIO_BUCKET:refound-images}
ads-bucket: ${MINIO_ADS_BUCKET:ads-media}
access-key: ${MINIO_ACCESS_KEY}
secret-key: ${MINIO_SECRET_KEY}
region: ${MINIO_REGION:us-east-1}

View File

@@ -0,0 +1,13 @@
databaseChangeLog:
- changeSet:
id: 2026-09-13-01-add-session-id-to-click
author: a.krylov
changes:
- addColumn:
tableName: click
columns:
- column:
name: session_id
type: VARCHAR(64)
constraints:
nullable: true

View File

@@ -0,0 +1,14 @@
databaseChangeLog:
- changeSet:
id: 012-advertising-media_key
author: a.krylov
changes:
- dropNotNullConstraint:
tableName: advertising
columnName: media_key
columnDataType: VARCHAR(512)
rollback:
- addNotNullConstraint:
tableName: advertising
columnName: media_key
columnDataType: VARCHAR(512)

View File

@@ -0,0 +1,38 @@
databaseChangeLog:
- changeSet:
id: 2026-09-22-01-drop-ad-id-from-impression
author: a.krylov
preConditions:
- onFail: MARK_RAN
- columnExists:
tableName: impression
columnName: ad_id
changes:
- sql:
sql: ALTER TABLE impression DROP COLUMN ad_id CASCADE
rollback:
- addColumn:
tableName: impression
columns:
- column:
name: ad_id
type: BIGINT
- changeSet:
id: 2026-09-22-02-drop-ad-id-from-click
author: a.krylov
preConditions:
- onFail: MARK_RAN
- columnExists:
tableName: click
columnName: ad_id
changes:
- sql:
sql: ALTER TABLE click DROP COLUMN ad_id CASCADE
rollback:
- addColumn:
tableName: click
columns:
- column:
name: ad_id
type: BIGINT

View File

@@ -0,0 +1,215 @@
databaseChangeLog:
- changeSet:
id: 2026-09-11-01-create-campaign-table
author: a.krylov
changes:
- createTable:
tableName: campaign
columns:
- column:
name: id
type: BIGSERIAL
constraints:
primaryKey: true
nullable: false
- column:
name: name
type: VARCHAR(255)
constraints:
nullable: false
- column:
name: status
type: VARCHAR(20)
defaultValue: PAUSED
constraints:
nullable: false
- column:
name: start_date
type: TIMESTAMP
constraints:
nullable: false
- column:
name: end_date
type: TIMESTAMP
constraints:
nullable: false
- column:
name: daily_impression_cap
type: INTEGER
defaultValueNumeric: 10
constraints:
nullable: false
- column:
name: created_at
type: TIMESTAMP
defaultValueComputed: CURRENT_TIMESTAMP
constraints:
nullable: false
- sql:
sql: >-
ALTER TABLE campaign
ADD CONSTRAINT chk_campaign_status
CHECK (status IN ('ACTIVE', 'PAUSED', 'DRAFT', 'FINISHED'))
rollback:
- sql:
sql: ALTER TABLE campaign DROP CONSTRAINT chk_campaign_status
- changeSet:
id: 2026-09-11-02-create-advertising-table
author: a.krylov
changes:
- createTable:
tableName: advertising
columns:
- column:
name: id
type: BIGSERIAL
constraints:
primaryKey: true
nullable: false
- column:
name: campaign_id
type: BIGINT
constraints:
nullable: false
foreignKeyName: fk_advertising_campaign
references: campaign(id)
- column:
name: type
type: VARCHAR(10)
constraints:
nullable: false
- column:
name: media_key
type: VARCHAR(512)
constraints:
nullable: false
- column:
name: target_url
type: VARCHAR(1024)
constraints:
nullable: false
- column:
name: weight
type: INTEGER
defaultValueNumeric: 1
constraints:
nullable: false
- column:
name: transcoding_status
type: VARCHAR(20)
defaultValue: PENDING
constraints:
nullable: false
- column:
name: created_at
type: TIMESTAMP
defaultValueComputed: CURRENT_TIMESTAMP
constraints:
nullable: false
- sql:
sql: >-
ALTER TABLE advertising
ADD CONSTRAINT chk_advertising_type
CHECK (type IN ('IMAGE', 'VIDEO'))
- sql:
sql: >-
ALTER TABLE advertising
ADD CONSTRAINT chk_advertising_transcoding_status
CHECK (transcoding_status IN ('PENDING', 'PROCESSING', 'READY', 'FAILED'))
- createIndex:
tableName: advertising
indexName: idx_advertising_campaign_id
columns:
- column:
name: campaign_id
rollback:
- sql:
sql: ALTER TABLE advertising DROP CONSTRAINT chk_advertising_type
- sql:
sql: ALTER TABLE advertising DROP CONSTRAINT chk_advertising_transcoding_status
- changeSet:
id: 2026-09-11-03-create-impression-table
author: a.krylov
changes:
- createTable:
tableName: impression
columns:
- column:
name: id
type: BIGSERIAL
constraints:
primaryKey: true
nullable: false
- column:
name: advertising_id
type: BIGINT
constraints:
nullable: false
foreignKeyName: fk_impression_advertising
references: advertising(id)
- column:
name: user_id
type: BIGINT
- column:
name: session_id
type: VARCHAR(64)
constraints:
nullable: false
- column:
name: shown_at
type: TIMESTAMP
defaultValueComputed: CURRENT_TIMESTAMP
constraints:
nullable: false
- createIndex:
tableName: impression
indexName: idx_impression_advertising_id
columns:
- column:
name: advertising_id
- createIndex:
tableName: impression
indexName: idx_impression_user_shown_at
columns:
- column:
name: user_id
- column:
name: shown_at
- changeSet:
id: 2026-09-11-04-create-click-table
author: a.krylov
changes:
- createTable:
tableName: click
columns:
- column:
name: id
type: BIGSERIAL
constraints:
primaryKey: true
nullable: false
- column:
name: advertising_id
type: BIGINT
constraints:
nullable: false
foreignKeyName: fk_click_advertising
references: advertising(id)
- column:
name: user_id
type: BIGINT
- column:
name: clicked_at
type: TIMESTAMP
defaultValueComputed: CURRENT_TIMESTAMP
constraints:
nullable: false
- createIndex:
tableName: click
indexName: idx_click_advertising_id
columns:
- column:
name: advertising_id

View File

@@ -0,0 +1,66 @@
databaseChangeLog:
- changeSet:
id: 2026-09-22-01-create-fullscreen-advertising-table
author: a.krylov
changes:
- createTable:
tableName: fullscreen_advertising
columns:
- column:
name: id
type: BIGSERIAL
constraints:
primaryKey: true
nullable: false
- column:
name: media_key
type: VARCHAR(512)
- column:
name: target_url
type: VARCHAR(1024)
- column:
name: status
type: VARCHAR(20)
defaultValue: DRAFT
constraints:
nullable: false
- column:
name: transcoding_status
type: VARCHAR(20)
defaultValue: PENDING
constraints:
nullable: false
- column:
name: created_at
type: TIMESTAMP
defaultValueComputed: CURRENT_TIMESTAMP
constraints:
nullable: false
- sql:
sql: >-
ALTER TABLE fullscreen_advertising
ADD CONSTRAINT chk_fullscreen_ad_status
CHECK (status IN ('DRAFT', 'ACTIVE', 'INACTIVE'))
- sql:
sql: >-
ALTER TABLE fullscreen_advertising
ADD CONSTRAINT chk_fullscreen_ad_transcoding_status
CHECK (transcoding_status IN ('PENDING', 'PROCESSING', 'READY', 'FAILED'))
# Гарантирует ровно один активный ролик на уровне БД, не только в коде:
# партиционный уникальный индекс — если ДВЕ строки одновременно имеют
# status='ACTIVE', обе будут иметь одинаковое значение 'ACTIVE' в этом
# индексе, что нарушит уникальность.
- sql:
sql: >-
CREATE UNIQUE INDEX uq_fullscreen_ad_single_active
ON fullscreen_advertising (status)
WHERE status = 'ACTIVE'
rollback:
- sql:
sql: DROP INDEX uq_fullscreen_ad_single_active
- sql:
sql: ALTER TABLE fullscreen_advertising DROP CONSTRAINT chk_fullscreen_ad_status
- sql:
sql: ALTER TABLE fullscreen_advertising DROP CONSTRAINT chk_fullscreen_ad_transcoding_status
- dropTable:
tableName: fullscreen_advertising

View File

@@ -19,4 +19,9 @@ databaseChangeLog:
- include: { file: db/changelog/create/009-create-statistic.yaml }
- include: { file: db/changelog/alter/011-alter-posts-district-length.yaml}
- include: { file: db/changelog/add/014-add-reward-posts.yaml }
- include: { file: db/changelog/add/015-add-desc-reward-posts.yaml }
- include: { file: db/changelog/add/015-add-desc-reward-posts.yaml }
- include: { file: db/changelog/create/010-add-advertising.yaml }
- include: { file: db/changelog/add/016-add-sessionid-click.yaml }
- include: { file: db/changelog/alter/012-advertising-media_key.yaml }
- include: { file: db/changelog/alter/013-del-ad_id-click-impression.yaml }
- include: { file: db/changelog/create/011-create-fullscreen-ads.yaml }