dbt init 명령어
dbt init 명령어
dbt init 명령어는 dbt 사용을 시작할 수 있게 도와줘요. 새 프로젝트를 만들고 연결 프로필을 설정하며, 기존 프로젝트에서도 프로필을 빠르게 구성해 줘요.
출처: 문서
본문
dbt init은 dbt 사용을 시작하는 데 도움을 줘요!
새 프로젝트
처음으로 이 도구를 사용한다면 다음을 물어봐요:
- 프로젝트 이름을 정해 달라고 요청
- 어떤 데이터베이스 어댑터를 쓰는지 물어봄(또는 Supported Data Platforms 참조)
account,user,password등 dbt가 해당 데이터베이스에 연결하는 데 필요한 각 정보를 프롬프트로 요청
그다음 이렇게 해요:
- 프로젝트 이름과 샘플 파일이 있는 새 폴더를 만들어서 dbt를 시작할 수 있게 해줘요
- 로컬 머신에 연결 프로필을 생성해요. 기본 위치는
~/.dbt/profiles.yml이에요. 프로필 설정에 대한 자세한 내용을 읽어보세요. .env(dbt v1.12부터),target/,dbt_packages/,logs/를 포함한.gitignore파일을 생성해서 로컬 자격 증명과 빌드 아티팩트가 기본적으로 버전 관리에서 제외되게 해줘요.
dbt init으로 프로젝트를 초기화할 때는 --profile 플래그를 포함해 새 프로필을 만들 대신 profile: 키로 사용할 기존 profiles.yml을 지정하세요. 예: dbt init --profile profile_name.
profile이 profiles.yml에 없거나 명령어가 기존 프로젝트 안에서 실행되면 오류가 발생해요.
커맨드라인 옵션
dbt init --help에는 전역 플래그(모든 dbt 명령어에 적용)와 소수의 init 전용 옵션이 포함돼요. 가장 흔히 쓰는 init 옵션은:
PROJECT_NAME(선택적 위치 인자): 만들 프로젝트 폴더의 이름. 생략하면dbt init이 프로젝트 이름을 프롬프트로 물어봐요.--profile PROFILE_NAME: 프롬프트로 만들거나 설정하는 대신profiles.yml의 기존 프로필 이름을 사용해요.-s,--skip-profile-setup: 인터랙티브 프로필 설정을 건너뛰어요.
dbt init [PROJECT_NAME] [--profile PROFILE_NAME] [--skip-profile-setup]
dbt init에도 적용되는 전역 명령어 옵션은 Command line options를 참고하세요.
기존 프로젝트
방금 클론하거나 다운로드한 기존 dbt 프로젝트가 있다면 dbt init으로 연결 프로필을 설정해 빠르게 작업을 시작할 수 있어요. 위와 같이 연결 정보를 프롬프트로 물어보고, 프로젝트의 profile 이름을 사용해 프로필을 로컬 profiles.yml에 추가하거나 파일이 없으면 생성해요.
profile_template.yml
dbt init은 profile_template.yml이라는 파일을 찾아 연결 정보를 어떻게 프롬프트로 물어볼지 알아요. 이 파일을 두 곳에서 찾아요:
- Adapter plugin: 최소 Postgres 프로필은 무엇일까요? 각 필드의 타입과 기본값은 무엇일까요? 이 정보는
dbt/include/postgres/profile_template.yml파일에 저장돼요. 어댑터 플러그인 유지 관리자라면 플러그인에도profile_template.yml을 추가하는 것을 강력히 권장해요. 자세한 내용은 Build, test, document, and promote adapters 가이드를 참고하세요. - Existing project: 기존 프로젝트 유지 관리자라면 새 사용자가 데이터베이스에 빠르고 쉽게 연결하도록
dbt_project.yml과 함께 프로젝트 루트에 커스텀profile_template.yml을 포함할 수 있어요. 공통 연결 속성은fixed에 값을 설정하고, 사용자별 속성은prompts에 두되 원하는 대로 커스텀 힌트와 기본값을 지정하세요.
profile_template.yml
fixed:
account: abc123
authenticator: externalbrowser
database: analytics
role: transformer
type: snowflake
warehouse: transforming
prompts:
target:
type: string
hint: your desired target name
user:
type: string
hint: [email protected]
schema:
type: string
hint: usually dbt_<yourname>
threads:
hint: "your favorite number, 1-10"
type: int
default: 8
$ dbt init
Running with dbt=1.0.0
Setting up your profile.
user ([email protected]): [email protected]
schema (usually dbt_<yourname>): dbt_summerintern
threads (your favorite number, 1-10) [8]: 6
Profile internal-snowflake written to /Users/intern/.dbt/profiles.yml using project's profile_template.yml and your supplied values. Run 'dbt debug' to validate the connection.
더 알아보기 (Learn more)
- dbt debug 명령어 — 연결 검증
- 프로필 설정