version: 2

models:

  - name: STREAMS_BY_TRACK_FEED_DISTRIBUTOR_DAILY_RECENT_DBT
    description:
      A table containing number of streams, skips and saves for a track on a date / store level.
    tests:
      - unique:
          column_name: "concat(track_id, '-', download_activity_date, '-', feed_id, '-', distributor)"
    columns:
      - name: distributor
        tests:
          - not_null
      - name: track_id
        tests:
          - not_null
      - name: download_activity_date
        tests:
          - not_null
      - name: feed_id
        tests:
          - not_null
      - name: store_id
        tests:
          - not_null
      - name: label_id
      - name: product_id
        tests:
          - not_null
      - name: isrc
        tests:
          - not_null
      - name: streams
        tests:
          - not_null
      - name: skips
      - name: saves

  - name: STREAMS_BY_TRACK_FEED_DISTRIBUTOR_DAILY_HISTORY_DBT
    config:
      tags: history
    description:
      A table containing number of streams, skips and saves for a track on a date / store level.
    tests:
      - unique:
          column_name: "concat(track_id, '-', download_activity_date, '-', feed_id, '-', distributor)"
    columns:
      - name: distributor
        tests:
          - not_null
      - name: track_id
        tests:
          - not_null
      - name: download_activity_date
        tests:
          - not_null
      - name: feed_id
        tests:
          - not_null
      - name: store_id
        tests:
          - not_null
      - name: label_id
      - name: product_id
        tests:
          - not_null
      - name: isrc
        tests:
          - not_null
      - name: streams
        tests:
          - not_null
      - name: skips
      - name: saves


  - name: STREAMS_BY_TRACK_FEED_DISTRIBUTOR_ROLLUP_DBT
    description:
      A table containing all time streams, number of streams for the last 7 days and the week before that,
      for 28 days for a track on a store level.
    tests:
      - unique:
          column_name: "concat(track_id, '-', feed_id, '-', distributor)"
    columns:
      - name: distributor
        tests:
          - not_null
      - name: track_id
        tests:
          - not_null
      - name: feed_id
        tests:
          - not_null
      - name: store_id
        tests:
          - not_null
      - name: product_id
        tests:
          - not_null
      - name: label_id
      - name: isrc
        tests:
          - not_null
      - name: streams_7_days
        tests:
          - not_null
      - name: streams_7_days_prev
        tests:
          - not_null
      - name: streams_28_days
        tests:
          - not_null
      - name: streams_all_time
        tests:
          - not_null
  - name: STREAMS_BY_TRACK_FEED_DISTRIBUTOR_ROLLUP_PRODUCT_TRANSFER_DBT
    config:
      tags: ['product_transfer']
    description:
      A table containing all time streams, number of streams for the last 7 days and the week before that,
      for 28 days for a track on a store level. One row per (track, feed, store, distributor, product, label_id, subaccount_id),
      where label_id / subaccount_id come from PRODUCT_OWNERSHIP_ACCESS and may be a current or former owner.
    tests:
      - unique:
          column_name: "concat(track_id, '-', feed_id, '-', distributor, '-', store_id, '-', product_id, '-', coalesce(label_id, -1), '-', coalesce(subaccount_id, -1))"
    columns:
      - name: distributor
        tests:
          - not_null
      - name: track_id
        tests:
          - not_null
      - name: feed_id
        tests:
          - not_null
      - name: store_id
        tests:
          - not_null
      - name: product_id
        tests:
          - not_null
      - name: label_id
      - name: subaccount_id
      - name: isrc
        tests:
          - not_null
      - name: streams_7_days
        tests:
          - not_null
      - name: streams_7_days_prev
        tests:
          - not_null
      - name: streams_28_days
        tests:
          - not_null
      - name: streams_all_time
        tests:
          - not_null

